0

I'm trying to create a (Pokemon) project just for fun. My friend tried it and he said that the moves' name shouldn't be checked so strictly. Now it's like:

string Movename = "Dark Pulse";
string ChosenMovename = Console.ReadLine();

if (Movename == ChosenMovename)
{
    Console.WriteLine(...);
}
else
{
    Console.WriteLine("Didn't you mistype something?");
    goto P1; //P1 is the end of the code -> the program closes
}

He said I should use an array for different ways of typing like Dark Pulse, dark pulse,Dark pulse,dark Pulse,DARK PULSE (I hope you see the difference). And you know if he writes down dark pulse then (Movename == ChosenMovename) will be false because "Dark Pulse" and "dark pulse" are not the same. So, how NOT to check capital letters in strings?

JNevill
  • 46,980
  • 4
  • 38
  • 63
Jazehin
  • 1
  • 2
  • 1
    It this a console application? Can you use numbers instead? – Patrick Hofman Nov 26 '18 at 14:17
  • 1
    `string.Equals` with `StringComparison.OrdinalIgnoreCase` – Igor Nov 26 '18 at 14:18
  • 3
    `string.Equals(Movename, ChosenMovename, StringComparison.OrdinalIgnoreCase)` – Rand Random Nov 26 '18 at 14:18
  • If the code is expecting an input from a finite known list of possible inputs, consider providing the user with a means of selecting from that list instead of blindly typing it. This provides a friendlier user experience while reducing the potential for typos in the input. – David Nov 26 '18 at 14:25

1 Answers1

0

Convert both strings to upper (or lower) case in the comparison.

if (Movename.ToUpper() == ChosenMovename.ToUpper())

Or, as the others have pointed out, use the built-in case insensitive string comparison function:

if (string.Equals(Movename, ChosenMovename, StringComparison.OrdinalIgnoreCase))
Robin Bennett
  • 3,192
  • 1
  • 8
  • 18