Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/243.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# 从返回streamreader中查找错误代码_C#_Php - Fatal编程技术网

C# 从返回streamreader中查找错误代码

C# 从返回streamreader中查找错误代码,c#,php,C#,Php,我需要的是从字符串返回的错误代码,我可以在php中执行,但它需要转换为C,任何人都可以将此代码转换为C 串 <?xml version="1.0" encoding="UTF-8"?> <nma> <error code="402" resettimer="TIMELEFT"></error> </nma> preg_match("/<error code=\"(.*?)\".*>(.*?)<\/error&

我需要的是从字符串返回的错误代码,我可以在
php
中执行,但它需要转换为C,任何人都可以将此代码转换为C

<?xml version="1.0" encoding="UTF-8"?>
<nma>
    <error code="402" resettimer="TIMELEFT"></error>
</nma>

preg_match("/<error code=\"(.*?)\".*>(.*?)<\/error>/i", $return, $out);


// return $out[1] = 200;

预匹配(“/(*?)/i”,$return,$out);
//返回$out[1]=200;
我试过了,但没有成功

foreach (Match m in Regex.Matches(response, "<error code=\"(.*?)\".*>(.*?)</error>")){
         Console.WriteLine("'{0}' found at index {1}.", 
                           m.Value, m.Index);
foreach(在Regex.Matches(响应,(.*))中匹配m){
WriteLine(“{0}”位于索引{1}.”,
m、 值(m.Index);

我想您正在寻找房产:

string response = @"<?xml version=""1.0"" encoding=""UTF-8""?>
                    <nma>
                        <error code=""402"" resettimer=""TIMELEFT"">test</error>
                    </nma>";

foreach (Match m in Regex.Matches(response, "<error code=\"(.*?)\".*>(.*?)</error>"))
{
    Console.WriteLine(m.Groups[1]); // 402
    Console.WriteLine(m.Groups[2]); // test
}
string-response=@”
测试
";
foreach(在Regex.Matches(响应,(.*))中匹配m)
{
Console.WriteLine(m.Groups[1]);//402
Console.WriteLine(m.Groups[2]);//test
}

为什么不使用xml解析器?Regex不用于解析xml