使用Split的方法
Split就是对字符串进行分割。




参数
- separator :
- 分隔此实例中子字符串的 Unicode 字符数组、不包含分隔符的空数组或空引用。
返回值
如果此实例不包含 separator 中的任何字符,则为由包含此实例的单个元素组成的数组。
如果此实例由 separator 中的一个或多个字符分隔,则为子字符串数组。
如果出现空白字符,而且 separator 为空引用或不包含分隔符,则返回此实例中由空白字符分隔的子字符串数组。
对于其中有两个相邻分隔符的任何子字符串,或者在此实例的开头或结尾找到分隔符,则返回 Empty。分隔符不包括在子字符串中。
例如:
输入 | 分隔符 | 输出 |
---|---|---|
"42, 12, 19" | new Char[] {',', ' '} | {"42", "", "12", "", "19"} |
"42..12..19" | new Char[] {'.'} | {"42", "", "12", "", "19"} |
"Banana" | new Char[] {'.'} | {"Banana"} |
"Darb/nSmarba" | new Char[] {} | {"Darb", "Smarba"} |
"Darb/nSmarba" | 空 | {"Darb", "Smarba"} |
看下面的例子:






















结果:acdefacdefacdfe.
如果希望使用多个字符进行分割看下面的例子:























最后来个更复杂的 就是使用正则表达式:


























通过以上3个例子我简单的介绍了Split的用法, 当然最后一种值得推荐。
本文地址:http://www.45fan.com/a/question/71315.html