c# insensitive to capital letters by console | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

c# insensitive to capital letters by console

Hello, Can anybody tell me, please, how can I do to make c# insensitive to captital letters when introducing a string by console?? For example: cw-Do you want ...., yes or not? cr- yes OR YES OR Yes OR yES...

20th Aug 2020, 9:31 AM
Daniel Montero Román
Daniel Montero Román - avatar
2 Answers
+ 3
Four ways to upper- or lowercase a C# string When we uppercase a string, its characters are converted into capital letters. And when we lowercase, those characters are turned into regular letters. Of course that only affects characters that have a cased alternative. Most writing systems, like the Latin and Cyrillic alphabets, have a cased version for every word character. But non-word characters (such as 1, !, and ;) remain the same when we change a string's case. C# has four string methods that change a string's entire casing: ToUpper() uppercases a string with casing rules from a specific culture. ToUpperInvariant() uppercases a string in a culture-insensitive way. ToLower() lowercases a string with casing rules from some culture. ToLowerInvariant() lowercases a string independent of a specific culture. For more see:https://kodify.net/csharp/strings/uppercase-lowercase/
20th Aug 2020, 9:50 AM
Matias
Matias - avatar
+ 1
For case insensitive comparison use String.Compare() function with 3rd argument set to true. Read the docs https://docs.microsoft.com/en-us/dotnet/api/system.string.compare?view=netcore-3.1#System_String_Compare_System_String_System_String_System_Boolean_ string yes ="yes"; string yEs ="yEs"; if(String.Compare(yes,yEs,true)==0){ Console.Write("Equal"); }
20th Aug 2020, 9:51 AM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar