C# 分割字符串几种方式小结
2021-02-03 09:15
标签:remove temp new 去除 each write OLE 多个 ons 1、普通分割字符串方式 string str = "a,b,c"; foreach (string s in arr) ->输出结果: a 2、利用字符串进行分割字符串方式 string str = "a字体b字体c字体d字体e"; foreach (string s in arr) ->输出结果: a 3、多个字符分割字符串方式 string str = "a,b,c@d$e"; foreach (string s in arr) 或 string str = "a,b,c@d$e"; foreach (string s in arr) ->输出结果: a 4、分割字符串且去除空字符数组方式 string str = "a,,,b,c,d,e"; foreach (string s in arr) ->输出结果: a string str = "a,,,b,c,d,e"; ->输出结果: a 5、分割字符串且不区用作分割字符串的字符的大小写方式 string str = "bacAdae"; ->输出结果: b C# 分割字符串几种方式小结 标签:remove temp new 去除 each write OLE 多个 ons 原文地址:https://www.cnblogs.com/zerosymbol/p/11516136.html
string[] arr = str.Split(‘,‘);
{
Console.WriteLine(s);
}
b
c
string strTemp = "字体";
string[] arr = Regex.Split(str, strTemp, RegexOptions.IgnoreCase);
{
Console.WriteLine(s);
}
b
c
d
e
char[] charTemp = {‘,‘, ‘@‘, ‘$‘};
string[] arr = str.Split(charTemp);
{
Console.WriteLine(s);
}
string[] arr = str.Split(new char[] { ‘,‘, ‘@‘, ‘$‘ });
{
Console.WriteLine(s);
}
b
c
d
e
string[] arr = str.Split(‘,‘);
{
Console.WriteLine(s);
}
b
c
d
e
string[] arr = str.Split(new char[] { ‘,‘ }, StringSplitOptions.RemoveEmptyEntries);
foreach (string s in arr)
{
Console.WriteLine(s);
}
b
c
d
e
string[] arr = Regex.Split(str, "a", RegexOptions.IgnoreCase);
foreach (string s in arr)
{
Console.WriteLine(s);
}
c
d
e