v_kns v_kns - 7 months ago 53
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?


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