aspnet中字符串截取问题,急

来源:互联网  时间:2016/6/30 21:13:41

关于网友提出的“ aspnet中字符串截取问题,急”问题疑问,本网通过在网上对“ aspnet中字符串截取问题,急”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:

问题: aspnet中字符串截取问题,急
描述:

string pic="[1:15.00%];[2:0.00%];[3:0.00%];[4:0.00%];[5:0.00%];[6:0.00%];[7:0.00%];[8:0.00%];[9:0.00%];[10:0.00%];[11:0.00%];[12:0.00%];[13:0.00%];[14:0.00%];[15:0.00%];[16:0.00%];[17:0.00%];[18:0.00%];[19:0.00%];[20:0.00%];[21:0.00%];[22:0.00%];[23:0.00%];[24:0.00%];[25:0.00%];[26:0.00%];[27:0.00%];[28:0.00%];[29:0.00%];[30:0.00%];[31:0.00%];";
如何把这样的一个字符串把“:”前后的值分别截取出来?
最好能储存到List中


解决方案1:

少了个后面的


string pic = "[1:15.00%];[2:0.00%];[3:0.00%];[4:0.00%];[5:0.00%];[6:0.00%];[7:0.00%];[8:0.00%];[9:0.00%];[10:0.00%];[11:0.00%];[12:0.00%];[13:0.00%];[14:0.00%];[15:0.00%];[16:0.00%];[17:0.00%];[18:0.00%];[19:0.00%];[20:0.00%];[21:0.00%];[22:0.00%];[23:0.00%];[24:0.00%];[25:0.00%];[26:0.00%];[27:0.00%];[28:0.00%];[29:0.00%];[30:0.00%];[31:0.00%];";
Regex regex1 = new Regex(@"(?<=\[)\d+(?=:)");
Regex regex2 = new Regex(@"(?<=:).+?(?=%)"); 
List list1 = new List();
List list2 = new List();
foreach (Match match in regex1.Matches(pic))
{
    list1.Add(Convert.ToInt32(match.Value));
    Response.Write(match.Value + " ");
    //1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
}
foreach (Match match in regex2.Matches(pic))
{
    list2.Add(match.Value + " ");
    Response.Write(match.Value + " ");
    //15.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 
}

上一篇求个关于 航空公司积分管理 或者银行积分管理的思路!
下一篇Enter键响应按钮
明星图片
相关文章
《 aspnet中字符串截取问题,急》由码蚁之家搜集整理于网络,
联系邮箱:mxgf168#qq.com(#改为@)