If you start to check for cases, you need to check all combinations.
help, helP, heLp, heLP, hElp, hElP, hELp, hELP, Help, HelP, HeLp, HeLP, HElp, HElP, HELp and HELP.
The best solution is to force to lower case or upper case, your choice.
public static String ParseCmd(String rawCmd)
{
string TmpCmd= rawCmd.ToUpper();
if (TmpCmd.Equals("HELP")
{
return "help!";
}
else if (TmpCmd.Equals("QUIT")
{
return "Quit!";
}
else if (TmpCmd.Equals("MYCOMMAND")
{
return "My Command!";
}
else
{
return "Unknown Command!";
}
return null;
}
[Update]
if
and
switch
perform the same. The difference is that
if
allow more sophisticated conditions.
For hundred or thousands of commands, other techniques are to be used to prevent having to check every possibilities.
More details would be needed to determinate which technique is best.