Missing numbersについては、elseステートメントに進みます。 "The"を入力すると読み込まれますが、2つの数字を入力すると、カウントはまだ0
と表示されます。ラベルを移動して変更する代わりにelseステートメントを返します。どうして?Regex Count not working
protected void submit_Click(object sender, EventArgs e)
{
string input = textbox.Text;
string s = textbox.ToString();
input = input.Trim();
MatchCollection matches = Regex.Matches(s, @"\d+");
string[] result = matches.Cast<Match>()
.Take(2)
.Select(match => match.Value)
.ToArray();
if (input.StartsWith("The") || input.StartsWith("the"))
{
if (matches.Count == 2)
{
alarm.Text = result[0];
server.Text = result[1];
}
else
{
string script = "alert(\"Missing Number(s)!\");";
ScriptManager.RegisterStartupScript(this, GetType(),
"ServerControlScript", script, true);
}
}
}
正確な入力文字列は何ですか? –
The 3 5 ------- – LoLo
'string s = textbox.ToString();'を 'string s = textbox.Text;'に置き換える必要があります。そうでなければ、別の文字列を解析します:) –