✅ Ignore case sensitive string in array.

Is there a better or shorter way of ignoring case sensitive strings in a array?
8 Replies
77_105_114_111
77_105_114_111OP5d ago
string[] question1 = { "Tesla", "Mercedes"};


try
{

Console.WriteLine("Welcome to the C# quiz.");

//Question 1.
Console.WriteLine("1. Enter cars name: ");
Text1 = Console.ReadLine();



if (Text1 == question1[0].ToLower() || Text1 == question1[0].ToUpper())
{
Console.WriteLine("Correct answer");
Score++;
}
string[] question1 = { "Tesla", "Mercedes"};


try
{

Console.WriteLine("Welcome to the C# quiz.");

//Question 1.
Console.WriteLine("1. Enter cars name: ");
Text1 = Console.ReadLine();



if (Text1 == question1[0].ToLower() || Text1 == question1[0].ToUpper())
{
Console.WriteLine("Correct answer");
Score++;
}
Even this way is not %100 because if the user enters just one capital letter it wont work
Keswiik
Keswiik5d ago
yeah, use the ignore case options when checking if strings are equal
Keswiik
Keswiik5d ago
How to compare strings - C#
Learn how to compare and order string values, with or without case, with or without culture specific ordering.
77_105_114_111
77_105_114_111OP5d ago
ok I'll read through the link, thanks This removes case sensitive letters for a string variable Text1.Equals(Tesla, StringComparison.OrdinalIgnoreCase) but it does not work with array
Keswiik
Keswiik5d ago
wut show code with what you're trying to do
77_105_114_111
77_105_114_111OP5d ago
I made a error, It's working now 🙂 thank you
sibber
sibber5d ago
@77_105_114_111 $close
MODiX
MODiX5d ago
If you have no further questions, please use /close to mark the forum thread as answered

Did you find this page helpful?