Home > OS >  how can I store specific characters that were entered into a textbox in a variable in vb.net?
how can I store specific characters that were entered into a textbox in a variable in vb.net?

Time:06-08

Essentially what I am trying to do is filter an input and store only a specific set of characters from a textbox in a variable to use for a comparison. For example, if the user enters in a code like 'C1TEST' into the text box, I am looking for a way to take that string and store the prefix 'C1' in a variable. If the user entered 'USTEST' I would want the value 'US' stored in that variable. Currently I only need the first two characters of the string, nothing more, nothing less.

Any and all advice on this issue would be greatly appreciated.

CodePudding user response:

Use substring function...

Dim First2Char As String = tbObservacoes.Text.Substring(0, 2) ' (starting index, length)
MsgBox(First2Char)

Using the way I showed above, you will get 2 characters starting from position 0.

  • Related