Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用C查找字符串中的4个序列号#_C#_String - Fatal编程技术网

C# 使用C查找字符串中的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

我有一个大字符串,我想在字符串中找到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 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