I have a book for C# (CSharp) I only know a little bit but I am doing Console.Writeline stuff
I have this simple code here
Console.WriteLine("Please enter your name");
string name = Console.ReadLine();
if (name.Contains("no"))
{
Console.WriteLine("\nFine, don't put your name in");
}
else
{
Console.WriteLine("\nHello, " + name);
}
At the If part If you put "no" obviously it runs ("\nFine, don't put your name in") but if you put "no" as "No" "NO" "nO" it doesn't is there a code like name.Contains where it doesn't matter how you put the text it runs it anyway
Like SmallBasic Text.ConvertToLowerCase would convert your text to lowercase and then Run the IF
Thanks!
You should change Contains
to Equals
, if not a name like Noel will output "Fine don't put your name in"
if(name.Equals("no", StringComparison.CurrentCultureIgnoreCase))
{
}
You can convert the input to lower case characters:
if (name.ToLower().Contains("no"))
But why don't you like names like "Tino" or "Nora"? Better compare the whole string instead of just checking if it contains "no":
if (name.Equals("no", StringComparison.InvariantCultureIgnoreCase))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With