I’m creating a simple C# application where in it has a condition to capture both uppercase and lowercase of a letter.
This is my condition:
if( txtChord.Text == "A" || txtChord.Text == "a" && cbKeys.SelectedIndex == 6 ){
txtAnswer.Text = "B";
}
I’d like to do this more efficiently using regex.
Use
String.Compare(String, String, Boolean)method and supply true to the last argument to ignore case.The method above returns negative, 0 or positive number.
If you only want
boolvalue, you can useString.Equals(String, String, StringComparison)withStringComparison.OrdinalIgnoreCaseoption.