Search code examples
c#uppercaselowercasestring-function

How to validate both lowercase and uppercase input?


I have a winform application and I was wondering what is the c# code to validate both lowercase and uppercase input for string search comparison.Thank you.


Solution

  • One way is to use the method in the string class ToUpper() or ToLower() before validation.

    Something like

    string inputString = "inputfoo";
    
    if (inputString.ToUpper() == "INPUTFOO"){
      //do something, this is going to be executed
    }
    

    you can also check ToLower(), ToLowerInvariant, and ToUpperInvariant methods for further choices.