比如string str="11 12 13;14 9 16;";
如何把其中的数字提取出来,其中的数字0<n<21,11 12 13属于一组14 9 16属于另一组,也就是用 ; 分开我把检查条件写出来了是: Regex re = new Regex(@"^(([1-9]|1[0-9]|2[0-1])[\s|;]*)+;$");但是我不知道如何提取出来?
如何把其中的数字提取出来,其中的数字0<n<21,11 12 13属于一组14 9 16属于另一组,也就是用 ; 分开我把检查条件写出来了是: Regex re = new Regex(@"^(([1-9]|1[0-9]|2[0-1])[\s|;]*)+;$");但是我不知道如何提取出来?
解决方案 »
- 日期想减怎么总是报错啊~~
- c#实现SP收发短信,请问该如何实现
- WinForm中的DataGridView为何只能自定义列的背景色面不能设行的背景色?~~处女问....
- C#winfrom开发,在窗体中打开Excel文件
- 怎样吧Word嵌入到自己的窗体?不用axWebBrowser,还有其他办法吗?
- 能用代码设置ImageList图片的大小吗?
- 编写程序员日志系统程序
- unix下的tomcat问题!
- 在web页面怎样把dataset的数据一直保存下来呢,就是在翻页操作不连接数据库
- 在aspx的C#中如何才能向存貯過程變量@createdates偉入一個null值?
- 高分请教:datagridview中的消息函数
- 菜鸟的请教
string str="11 12 13;14 9 16;";
string[] str1 = new string[2];
str1 = str.Split(';');
for (int i = 0; i < str1.Length; i++)
{
Console.WriteLine(str1[i]);
}
ps 字符长度不定的 也就是说可能是 string str="11 12 13;14 9 16;15 16;18;";
MatchCollection mc = Regex.Matches(str, @"\d+");
foreach (Match m in mc)
{
Console.WriteLine(m.Value);
}
Console.ReadLine();
比如:string str="11 12 13;14 9 16;15 16;18;21 19;";
结果
11 12 13
14 9 16
15 16
18
21 19
MatchCollection mc = Regex.Matches(str, @"(\d+\s*)+(?=;)");
foreach (Match m in mc)
{
Console.WriteLine(m.Value);
}
Console.ReadLine();
Regex re = new Regex(@"(\d+\s*)+(?=;)");
MatchCollection mc = re.Matches(str);
foreach (Match m in mc)
{
Console.WriteLine(m.Value);
}
Console.ReadLine();