-2

重複の可能性:
応答 c# を誤ってチェックする

私はコードをもっている:

Match match = regex.Match(responseFromServer);
if (match.Success)
{
    var input = responseFromServer;
    var split = input.Split(':');
    var final = split[3];
    ProcessStartInfo mcStartInfo = new Shitocode;
    Process.Start(mcStartInfo);
    this.Close();
}
else if (responseFromServer == " Bad Login")
{
    MessageBox.Show("Uncorrect login/password!");
}
else if (responseFromServer == " Old version")
{
    MessageBox.Show("Launcher is old!");
}

最後の 2 つのインスペクションでメッセージ ボックスが表示されないのはなぜですか?

私は別のことをしようとしました:

if (match.Success)
{
    var input = responseFromServer;
    var split = input.Split(':');
    var final = split[3];
    ProcessStartInfo mcStartInfo = new Shitocode;
    Process.Start(mcStartInfo);
    this.Close();
}
else if (responseFromServer.Equals("Bad Login"))
{
    MessageBox.Show("Uncorrect login/password!");
}
else if (responseFromServer.Equals("Old Version"))
{
    MessageBox.Show("Launcher is old!");
}

間違ったパスワードを入力しましたが、メッセージボックスが開きません

4

3 に答える 3

0

おそらく、responseFromServerはチェックしている値と一致しません (不正なログイン、および古いバージョン)。ifシーケンスの最後に別のelse
を追加して、何が得られたかを確認してください。

if (match.Success)
{
   //your code
}
else if (responseFromServer.Equals("Bad Login"))
{
    MessageBox.Show("Uncorrect login/password!");
}
else if (responseFromServer.Equals("Old Version"))
{
    MessageBox.Show("Launcher is old!");
}
else
{
    MessageBox.Show("Cannot login, unknown response: " + responseFromServer)
}

コメント後に編集

正確なメッセージではなく、正確な文字列を含める必要があることがわかっている場合は、2 つresponseFromServer.Equals()を次のように変更できます。responseFromServer.Contains()

于 2012-11-05T09:49:56.397 に答える
0

ブレークポイントを設定し、コードを調べてresponseFromServer、2 つのケースで Copy this の値を確認し、コードで比較してください。「Bad Login」の前の最初のコード部分に空白があることに気付きましたが、その理由はわかりませんとりあえず。

于 2012-11-05T09:48:56.760 に答える