Reputation: 21
I have a text box in my form and I want to check if the first char is equal to something,
basically I want it to do this :
if(Textbox1.text.length(0) == "a")
{
do stuff
}
Upvotes: 1
Views: 772
Reputation: 11721
try smething like this:
Textbox1.Text.StartsWith("a") ? do something : do something else;
and if it is not just about first character then try something like:
Textbox1.Text.Contains("a") ? do something : do something else;
Upvotes: 0
Reputation: 186668
Eh, are you looking for
if (Textbox1.Text.StartsWith("a")) {
// do stuff
...
}
Upvotes: 3
Reputation:
you can do this by two ways...
one i mentioned in your question's comment
second is
if(myTextBox.Text[0] == 'B')
{
//do studd
}
Upvotes: 0
Reputation: 811
.length only returns an integer of length of the string. This will compare the first char with 'a'.
if(Textbox1.text[0] == 'a')
Upvotes: 3