文字列の配列があり、各文字列はフォームで構築されています"<x> <y>"
。y
で始まる場合'n'
、私のプログラムはそれを見つけることができないようです。
したがって、機能しない文字列は.
"w north",
"w n",
"walk n",
"walk north"
理由を説明していただけますか?
string[] next = { "next", "ne", "nx", "nxt" };
string[] yes = { "yes", "y" };
string[] no = { "no", "n" };
string[] clear = { "clear", "c" };
string[] help = { "help", "h" };
string[] walk =
{
"w north",
"w south",
"w west",
"w east",
"w n",
"w s",
"w w",
"w e",
"walk north",
"walk south",
"walk west",
"walk east" ,
"walk n",
"walk s",
"walk w",
"walk e"
};
//Checks if any input match the arrays
public string Input(string input)
{
input = input.ToLower();
if (next.Any(input.Contains))
{
return "next";
}
else if (yes.Any(input.Contains))
{
return "yes";
}
else if (no.Any(input.Contains))
{
return "no";
}
else if (clear.Any(input.Contains))
{
return "clear";
}
else if (help.Any(input.Contains))
{
return "help";
}
else if (walk.Any(input.Contains))
{
MessageBox.Show("test input");
Location C_locations = new Location();
C_locations.Change_location(input);
return "walk";
}
else
{
return "not found";
}
}
文字列: "w north"
、"w n"
、"walk n"
および"walk north"
は、コードのこの部分を実行する必要があります。
else if (walk.Any(input.Contains))
{
MessageBox.Show( "test input" );
Location C_locations = new Location();
C_locations.Change_location( input );
return "walk";
}