下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
Split(Char()) ?骰刈执??列,????列包含????绦???中,由指定的 Unicode 字元?列之元素所分隔的子字串。
代码如下 | 复制代码 |
1. public string[] Split(params char[] separator) string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"} string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"} |
Split(Char(), Int32) ?骰刈执??列,????列包含????绦???中,由指定的 Unicode 字元?列之元素所分隔的子字串。 ??悼芍付ㄒ?骰氐淖幼执?的康淖畲笾怠?/p>
代码如下 | 复制代码 |
2. public string[] Split(char[] separator, int count) string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"} string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"} |
Split(Char(), StringSplitOptions) ?骰刈执??列,????列包含???字串中,由指定的 Unicode 字元?列之元素所分隔的子字串。 ??抵付ㄊ欠?骰乜瞻椎年?列元素。
代码如下 | 复制代码 |
3. public string[] Split(char[] separator, StringSplitOptions options) string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素 string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素 |
Split(String(), StringSplitOptions) ?骰刈执??列,????列包含???字串中,由指定的字串?列之元素所分隔的子字串。 ??抵付ㄊ欠?骰乜瞻椎年?列元素。
代码如下 | 复制代码 |
4. public string[] Split(string[] separator, StringSplitOptions options) string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素 string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素 |
Split(Char(), Int32, StringSplitOptions) ?骰刈执??列,????列包含???字串中,由指定的 Unicode 字元?列之元素所分隔的子字串。 ??抵付?骰氐淖幼执?畲?的浚?约笆欠?骰乜盏年?列元素。
代码如下 | 复制代码 |
5. public string[] Split(char[] separator, int count, StringSplitOptions options) string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素 string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素 |
Split(String(), Int32, StringSplitOptions) ?骰刈执??列,????列包含???字串中,由指定的字串?列之元素所分隔的子字串。 ??抵付?骰氐淖幼执?畲?的浚?约笆欠?骰乜盏年?列元素。
代码如下 | 复制代码 |
6. public string[] Split(string[] separator, int count, StringSplitOptions options) |
需要注意的是没有重载函数public string[] Split(string[] separator)
好了这些都