我有一个大字符串,我想在字符串中找到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."
预期结果:“ 1946”和“ 4412”
string a=@"2015/10/13 is my birthday.I love this date1234!"
预期结果:“ 2015”和“ 1234”
string a=@"xx888xx88x9xx99x9999xx"
预期结果:“ 9999”
您可以使用正则表达式执行此操作,例如:
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);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句