-1

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.

kopelence
  • 173
  • 1
  • 2
  • 9

5 Answers5

2

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) { ... }
Fᴀʀʜᴀɴ Aɴᴀᴍ
  • 6,131
  • 5
  • 31
  • 52
0

Thanks to adv12 i found this piece of code to work perfectly

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

or

if (!textBox.Text.Contains("Fold"))
kopelence
  • 173
  • 1
  • 2
  • 9
0

Please use !textbox.Text.Contains("Fold") the exclamation mark means 'not'.

Steve Harris
  • 5,014
  • 1
  • 10
  • 25
0

You can get in a real time using TextChanged event of the TextBox. Much better way before users submits their result.

SH7
  • 732
  • 7
  • 20
0

Use if (!textbox.Text.Equals("Fold") = true) {...}