C#实现多个字符分割字符串的方法
string str = "1c2564c4c80ba89b2f2:0:0:|;bdaa2991b2f20a8fe43:0:1:|;";
//StringSplitOptions.RemoveEmptyEntries删除分割后可能出现的空元素
var strList = str.Split(new char[] { '|', ':', ';' }, StringSplitOptions.RemoveEmptyEntries)
.Where(a => a.Length > 2).Select(b => b).ToList();
foreach (var n in strList)
{
int index = strList.IndexOf(n);//获取当前n在List中的索引
Console.WriteLine("string str{0}={1}:", index, n);
}
输出结果:
string str0=1c2564c4c80ba89b2f2
string str1=bdaa2991b2f20a8fe43
输出结果:
string str0=1c2564c4c80ba89b2f2
string str1=bdaa2991b2f20a8fe43