Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading