根据字符的第一次出现来分割字符串 [英] Split string based on the first occurrence of the character

查看:78
本文介绍了根据字符的第一次出现来分割字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何根据首次出现的指定字符拆分C#字符串?假设我有一个带有值的字符串:

How can I split a C# string based on the first occurrence of the specified character? Suppose I have a string with value:

101,a,b,c,d

我想将其拆分为

101

a,b,c,d

那是第一次出现逗号字符.

That is by the first occurrence of comma character.

推荐答案

您可以使用 string.Split 指定要返回的子字符串数:

You can specify how many substrings to return using string.Split:

var pieces = myString.Split(new[] { ',' }, 2);

返回:

101
a,b,c,d

这篇关于根据字符的第一次出现来分割字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆