string ss="hhh#hhky###ggg##S";如何获得字符串ss中连续#号的起始位置与连续个数
既是要获得
第一个连续# # 在字符串ss的起始位置是3 连续个数为1
第二个连续# ### 在字符串ss的起始位置是8 连续个数为3
第三个连续# ## 在字符串ss的起始位置是14 连续个数为2多谢先.
既是要获得
第一个连续# # 在字符串ss的起始位置是3 连续个数为1
第二个连续# ### 在字符串ss的起始位置是8 连续个数为3
第三个连续# ## 在字符串ss的起始位置是14 连续个数为2多谢先.
然后你取出m中每个字符串的内容,333,444,这样不但可以得到字符串的长度,也知道其内容.
{
string ss="hhh#hhky###ggg##S";
string reg=@"[\#]+";
MatchCollection mc=Regex.Matches(ss,reg);
Console.WriteLine(mc.Count);
for(int i=0;i<mc.Count;i++)
{
Console.WriteLine("string # occured position at {0},length is {2},value is {1}",mc[i].Index,mc[i].Value,mc[i].Value.Length);
}
}