C# 使用C查找字符串中的4个序列号#
我有一个大字符串,我想在字符串中找到4个序列号。我怎么得到它 例如:C# 使用C查找字符串中的4个序列号#,c#,string,C#,String,我有一个大字符串,我想在字符串中找到4个序列号。我怎么得到它 例如: string a=@"I(1946) am a string and I have some character and number and some sign like 4412 but I must find 4 sequence numbers in this." var regex = new Regex(@"\d{4}"); string a=@"I(1946) am a string a
string a=@"I(1946) am a string and I have some character and number and some sign like 4412 but I must find 4 sequence numbers in this."
var regex = new Regex(@"\d{4}");
string a=@"I(1946) am a string and I have some character and number and some sign like 4412 but I must find 4 sequence numbers in this.";
foreach(Match match in regex.Matches(a))
Console.WriteLine(match.Value);
预期结果:“1946”和“4412”
string a=@"2015/10/13 is my birthday.I love this date1234!"
预期结果:“2015”和“1234”
string a=@"xx888xx88x9xx99x9999xx"
预期结果:“9999”您可以这样做,例如:
string a=@"I(1946) am a string and I have some character and number and some sign like 4412 but I must find 4 sequence numbers in this."
var regex = new Regex(@"\d{4}");
string a=@"I(1946) am a string and I have some character and number and some sign like 4412 but I must find 4 sequence numbers in this.";
foreach(Match match in regex.Matches(a))
Console.WriteLine(match.Value);
实例:
输出:
1946
4412
2015
1234
12345
-输出是什么?@UlugbekUmirov mm。。。我忘了考虑这个条件谢谢你的帮助,这个代码工作得很好!我想我必须多读正则表达式x