当前位置: 移动技术网 > IT编程>开发语言>c# > c#中分割字符串的几种方法

c#中分割字符串的几种方法

2019年07月18日  | 移动技术网IT编程  | 我要评论
单个字符分割 
string s="abcdeabcdeabcde"; 
string[] sarray=s.split('c'); 
foreach(string i in sarray) 
console.writeline(i.tostring()); 
输出下面的结果: 
ab 
deab 
deab 
de 


多个字符分割 
string s="abcdeabcdeabcde 
string[] sarray1=s.split(new char[3]{'c','d','e'}); 
foreach(string i in sarray1) 
console.writeline(i.tostring()); 
可以输出下面的结果: 
ab 
ab 
ab 

多个字符分割(正则表达式) 
string content="agcsmallmacsmallgggsmallytx"; 
string[]resultstring=regex.split(content,"small",regexoptions.ignorecase) 
foreach(string i in resultstring) 
console.writeline(i.tostring()); 
输出下面的结果:agc 
mac 
ggg 
ytx

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网