v_kns v_kns - 1 year ago 97
Vb.net Question

Shorten the length of an unknown string to one character in Visual Basic

I have to shorten the length of a string variable to one character. The problem arises as I don't know the length of the variable.

The code I have written has been designed to take a first name and surname and display them in a label in the format of SURNAME.INITIAL.

How would I be able to shorten the length of the variable FirstName to one letter?

Answer Source

Say you have the string Mary. To get the M you can do this:

Dim str As String
str = "Mary"

Dim first_char As Char
first_char = str .Substring(0, 1)

first_char will have the M

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download