Search code examples
c#stringtextboxcontains

C# How to check if Textbox doesn't contains string


i need to check if my textbox doesn't contain specific string "Fold". I used to do this like this

if (textbox.Text.Contains("Fold"){}
else { do stuff }

but now i need some alternative of this.


Solution

  • You need to reverse the boolean:

    if (!textBox.Text.Contains("Fold")) { ... }
    

    Or you can compare with false as @adv12 said:

    if (textBox.Text.Contains("Fold") == false) { ... }