这是我的代码
public void showMatch (string guess, string regx){
int outputCode;
MatchCollection mc = Regex.Matches (guess, regx);
foreach (Match m in mc) {
listOfTags [ctr] = m.Value;
ctr++;
}
checkOpeningTag = listOfTags [0];
checkClosingTag = listOfTags [1];
if (checkOpeningTag.Equals ("<h1>")) {
if (checkClosingTag.Equals ("</h1>")) {
outputCode = 3;
} else {
outputCode = 2;
}
} else {
outputCode = 1;
}
showError(outputCode);
}
public void showError(int checkError){
if (checkError == 1) {
error.text = "Sorry, no opening tag found.";
} else if(checkError == 2){
error.text = "Sorry, no closing tag found.";
}else if(checkError == 3){
error.text = "You got it right! Advancing to next level!";
}
}
如果我尝试输入&lt;&#39; h1&#39;&gt;和&lt;&#39; h1&#39;&gt; (无视&#39;),它会给我一个错误
Sorry no opening tag
但是当我尝试通过提交&lt;&#39; h1&#39;&gt;来纠正它时和&lt;&#39; / h1&#39;&gt; (无视&#39;),错误不会更新。它仍然说抱歉没有开口标记。
我尝试在showMatch函数结束时使用此代码
Debug.Log(outputCode);
我发现如果第一个输入结果为2,则每次结果总是为2.与if为结果相同,下一个结果为1.
我做错了什么?