467,136 Members | 1,328 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,136 developers. It's quick & easy.

TextBox.Text.Contains("X","Y","Z") ?

Hello,

I need to check if a textbox (of size = 1) contains a specific value
(character). I could say something like

If txt1.text.equals("X") or txt1.text.equals("Y")... then...

Ideally, I would like to do something like Sql --If txt1.text In ("X", "Y",
"Z") then...

txt1.Text.Contains only deals with one string at a time so I would be back
to square one:

If txt1.text.contains("X") or txt1.text.contains("Y")...

What is the most efficient way to perform a check like this?

Thanks,
Rich
Feb 1 '07 #1
  • viewed: 18766
Share:
7 Replies
On Feb 1, 12:58 pm, Rich <R...@discussions.microsoft.comwrote:
Hello,

I need to check if a textbox (of size = 1) contains a specific value
(character). I could say something like

If txt1.text.equals("X") or txt1.text.equals("Y")... then...

Ideally, I would like to do something like Sql --If txt1.text In ("X", "Y",
"Z") then...

txt1.Text.Contains only deals with one string at a time so I would be back
to square one:

If txt1.text.contains("X") or txt1.text.contains("Y")...

What is the most efficient way to perform a check like this?

Thanks,
Rich
Regex?

Thanks,

Seth Rowe

Feb 1 '07 #2
How about Instr("_X_Y_Z_")?

T

Rich wrote:
Hello,

I need to check if a textbox (of size = 1) contains a specific value
(character). I could say something like

If txt1.text.equals("X") or txt1.text.equals("Y")... then...

Ideally, I would like to do something like Sql --If txt1.text In ("X", "Y",
"Z") then...

txt1.Text.Contains only deals with one string at a time so I would be back
to square one:

If txt1.text.contains("X") or txt1.text.contains("Y")...

What is the most efficient way to perform a check like this?

Thanks,
Rich
Feb 1 '07 #3
Thanks all for your replies. Regex and Instr should do the trick.

"Rich" wrote:
Hello,

I need to check if a textbox (of size = 1) contains a specific value
(character). I could say something like

If txt1.text.equals("X") or txt1.text.equals("Y")... then...

Ideally, I would like to do something like Sql --If txt1.text In ("X", "Y",
"Z") then...

txt1.Text.Contains only deals with one string at a time so I would be back
to square one:

If txt1.text.contains("X") or txt1.text.contains("Y")...

What is the most efficient way to perform a check like this?

Thanks,
Rich
Feb 1 '07 #4
what about something like ...
Select Case TextBox1.Text

Case "X", "Y", "Z"

MsgBox("XYZ")

Case "A", "B", "C"

MsgBox("ABC")

Case Else

MsgBox("None of the options were entered")

End Select
"Rich" <Ri**@discussions.microsoft.comwrote in message
news:ED**********************************@microsof t.com...
Hello,

I need to check if a textbox (of size = 1) contains a specific value
(character). I could say something like

If txt1.text.equals("X") or txt1.text.equals("Y")... then...

Ideally, I would like to do something like Sql --If txt1.text In ("X",
"Y",
"Z") then...

txt1.Text.Contains only deals with one string at a time so I would be back
to square one:

If txt1.text.contains("X") or txt1.text.contains("Y")...

What is the most efficient way to perform a check like this?

Thanks,
Rich

Feb 1 '07 #5
Rich wrote:
Hello,

I need to check if a textbox (of size = 1) contains a specific value
(character). I could say something like

If txt1.text.equals("X") or txt1.text.equals("Y")... then...

Ideally, I would like to do something like Sql --If txt1.text In ("X", "Y",
"Z") then...

txt1.Text.Contains only deals with one string at a time so I would be back
to square one:

If txt1.text.contains("X") or txt1.text.contains("Y")...

What is the most efficient way to perform a check like this?

Thanks,
Rich
The IndexOf method of the string class looks for a string inside
another. It's like the InStr function, but for .NET.

If "XYZ".IndexOf(txt1.Text) <-1 Then

--
Göran Andersson
_____
http://www.guffa.com
Feb 1 '07 #6
Rich wrote:
I need to check if a textbox (of size = 1) contains a specific value
(character). I could say something like

If txt1.text.equals("X") or txt1.text.equals("Y")... then...
Personally, as soon as I see a checks for something like

thing = X or Y or Z

I reach for the Select Case construct - it's just easier on the eye.

Select Case txt1.text
Case "X", "Y", "Z"

Case Else

End Select

Then how about :

If txt1.Text.IndexOfAny(New Char() {"X"c, "Y"c, "Z"c}) = 0 Then
' :-)
End If

HTH,
Phill W.
Feb 2 '07 #7
Sorry I am behind the times but could use not use something like the
following for multiple checks?
If TextBox1.Text.IndexOfAny("X,Y,Z".ToCharArray) <-1 Then


"Rich" <Ri**@discussions.microsoft.comwrote in message
news:ED**********************************@microsof t.com...
Hello,

I need to check if a textbox (of size = 1) contains a specific value
(character). I could say something like

If txt1.text.equals("X") or txt1.text.equals("Y")... then...

Ideally, I would like to do something like Sql --If txt1.text In ("X",
"Y",
"Z") then...

txt1.Text.Contains only deals with one string at a time so I would be back
to square one:

If txt1.text.contains("X") or txt1.text.contains("Y")...

What is the most efficient way to perform a check like this?

Thanks,
Rich

Feb 8 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Robert W. | last post: by
16 posts views Thread by mj.redfox.mj@gmail.com | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.