日期:2014-05-17  浏览次数:20489 次

NET 截取字符串
字符串:c19a25bf7c303f6cb1c2564c4c80ba89:0:0:|;e8e046d661df1bdaa2991b2f20a8fe43:0:1:|;5e6a334d3c7fc785ddabb8330da20628:0:2:|;6abbc193317161b214fa695e2d 
如何截取为:
string str1=c19a25bf7c303f6cb1c2564c4c80ba89;
string str2=e8e046d661df1bdaa2991b2f20a8fe43;
strint str3=5e6a334d3c7fc785ddabb8330da20628;
string str4=6abbc193317161b214fa695e2d;

------解决方案--------------------
介个。。。。。字符串截取。。。
string str="c19a25bf7c303f6cb1c2564c4c80ba89:0:0:|;e8e046d661df1bdaa2991b2f20a8fe43:0:1:|;5e6a334d3c7fc785ddabb8330da20628:0:2:|;6abbc193317161b214fa695e2d "

string[] st=str.split('|');
foreach(string s in st)
{
string[] child=s.split(':');
response.write(child[0])
}
------解决方案--------------------
晕。还有个;号。response.write(child[0].TrimStart(';'))
------解决方案--------------------
C# code
string str = "c19a25bf7c303f6cb1c2564c4c80ba89:0:0:|;e8e046d661df1bdaa2991b2f20a8fe43:0:1:|;5e6a334d3c7fc785ddabb8330da20628:0:2:|;6abbc193317161b214fa695e2d";
            var atrList = str.Split(new char[] { '|', ':', ';' }, StringSplitOptions.RemoveEmptyEntries).Where(a => a.Length > 2).Select(b => b).ToList();
            foreach (var n in atrList)
            {
                int index = atrList.IndexOf(n);//获取当前n的索引 
                Console.WriteLine("string str{0}={1}:", index, n);
            }

------解决方案--------------------
string.split() 这个方法分离string,
------解决方案--------------------
选替换"|"为空;
再splist(';');
如果:是有规格的,则可以直接取:符号前面的值。