Click here to Skip to main content
15,881,831 members
Please Sign up or sign in to vote.
1.00/5 (5 votes)
See more:
I need to read the first 2 letters of a textbox.


Any idee's or links ?
Posted
Comments
Sergey Alexandrovich Kryukov 9-May-13 15:44pm    
Does this require ideas?!
—SA

Use TextBox.Text. And some minimal common sense.

Links? No, sorry. You did not bother to give us exact type name of the "TextBox" (do you know how many different type under this name are there?), but you can easily find a link using Google or Bing. Especially if you give it a fully-qualified name.

—SA
 
Share this answer
 
Comments
Maciej Los 9-May-13 16:31pm    
+5
Sergey Alexandrovich Kryukov 9-May-13 17:01pm    
Thank you, Maciej.
—SA
VB
Dim str as String
str = TextBox1.Text.Substring(0,2)
 
Share this answer
 
Comments
Maciej Los 9-May-13 16:31pm    
+5
Johnny J. 10-May-13 7:33am    
Just one thing: The OP will need to check that the text in the textbox is long enough, otherwise your code will generate an exception.

If TextBox1.Text.Length >=2 Then
str = TextBox1.Text.Substring(0,2)
End If

Sorry for pointing it out. It's common knowledge of course, but it doesn't seem like the OP has much experience in VB.NET...
ZurdoDev 10-May-13 7:46am    
Good catch. Thank you.
pdoxtader 10-May-13 8:57am    
Yes, and he may want to trim the text in the textbox - unless he wants the 2 possible empty spaces. ( str = TextBox1.Text.Trim.Substring(0,2) )

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900