tresehulyo
Member
- Joined
- Sep 1, 2009
- Messages
- 16
- Programming Experience
- Beginner
How to check if the string in textbox has space/spaces
then i will put it in if condition
then i will put it in if condition
If TextBox1.Text.Contains(" "c) Then
' ToDo: something
End If
[COLOR="Blue"]If [/COLOR]TextBox1.Text.Trim.Length = 0 [COLOR="blue"]Then[/COLOR]
[COLOR="SeaGreen"] 'Text box is empty of any text[/COLOR]
[COLOR="blue"]End If[/COLOR]
You can always edit the text for other functions.If TextBox1.Text.Contains(" ") = True Then
MessageBox.Show("You have spaces")
ElseIf TextBox1.Text.Contains(" ") = False Then
MessageBox.Show("You have no spaces")
End If
[COLOR="Blue"]If [/COLOR]TextBox1.Text.Contains(" ") = True [COLOR="blue"]Then[/COLOR]
MessageBox.Show([COLOR="Red"]"You have spaces"[/COLOR])
[COLOR="blue"]Else[/COLOR]
MessageBox.Show([COLOR="Red"]"You have no spaces"[/COLOR])
[COLOR="blue"]End If[/COLOR]
No reason to check twice....
VB.NET:[COLOR="Blue"]If [/COLOR]TextBox1.Text.Contains(" ") = True [COLOR="blue"]Then[/COLOR] MessageBox.Show([COLOR="Red"]"You have spaces"[/COLOR]) [COLOR="blue"]Else[/COLOR] MessageBox.Show([COLOR="Red"]"You have no spaces"[/COLOR]) [COLOR="blue"]End If[/COLOR]
No problem, just pointing out different ways of doing things. I come here for the same, to learn from the differences of others![]()