简体   繁体   中英

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM