如何读取括号内值的问题 一段这样的数据.A(c),B(n),C(u),D(r),E(t),F(8).......我想用一个for或foreach循环语句把括号里的值,即(c,n,u,r,t,8....)读出来,如何实现? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 假设A(c),B(n),C(u),D(r),E(t),F(8).......是一个stringstring [] temp = string.Split(',');string [] temp1 = new string[temp.length];for(int i = 0;i < temp.length;i ++){temp[i] = temp[i].substring(2,1);} 先用Split(',')给分成一个数组,然后对数组中每个串用Substring取第二到第三位的值,如果你的位数是不固定的那就用IndexOf取(和)位置,用Substring取两个位置间的串 用正则表达式吧。string a = "A(c),B(n),C(u),D(r),E(t),F(8)";System.Text.RegularExpressions.MatchCollection matchs = System.Text.RegularExpressions.Regex.Matches(a, @"\((?<value>[^\)])\)");foreach (System.Text.RegularExpressions.Match match in matchs){ Response.Write(match.Groups["value"].Value + "<br/>");} 用正则效率更好些string str = "A(c),B(n),C(u),D(r),E(t),F(8),G(10)......";string result = ""; string temp = str.Substring(str.IndexOf("("));while(temp.IndexOf("(") >= 0){ result += temp.Substring(1, temp.IndexOf(")")-1) + ","; temp = temp.Substring((temp.IndexOf("(", 1) < 0) ? 1 : temp.IndexOf("(", 1));}MessageBox.Show(result); 用asp.net 新建WebFrom的时候总提示collection.part 为空或不是对象,如何解决? asp.net2.0 有哪些开源而且很好的mvc 框架? 在网页上扫描本机的硬盘 为什么在已有的项目添加新窗体后无法正常运行? 这两个有什么区别 难题,请高手指点迷津 欢迎DotNet编程爱好者加入我的群! 编写了一个数据库层组件,使用Nunit测试完成,在Web页中使用却无效 两个问题!不会做,请教大家! 急!!!!!!!!求救 |M|今天面试:本以为很简单的问题,但却做不出来。非常郁闷 大家快来分析分析 想在网页上实现在线编辑WORD,EXCEL文件,都有哪些方法??哪些组件??
string [] temp = string.Split(',');
string [] temp1 = new string[temp.length];
for(int i = 0;i < temp.length;i ++)
{
temp[i] = temp[i].substring(2,1);
}
如果你的位数是不固定的那就用IndexOf取(和)位置,用Substring取两个位置间的串
string a = "A(c),B(n),C(u),D(r),E(t),F(8)";
System.Text.RegularExpressions.MatchCollection matchs = System.Text.RegularExpressions.Regex.Matches(a, @"\((?<value>[^\)])\)");
foreach (System.Text.RegularExpressions.Match match in matchs)
{
Response.Write(match.Groups["value"].Value + "<br/>");
}
string str = "A(c),B(n),C(u),D(r),E(t),F(8),G(10)......";
string result = "";
string temp = str.Substring(str.IndexOf("("));
while(temp.IndexOf("(") >= 0)
{
result += temp.Substring(1, temp.IndexOf(")")-1) + ",";
temp = temp.Substring((temp.IndexOf("(", 1) < 0) ? 1 : temp.IndexOf("(", 1));
}
MessageBox.Show(result);