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