Ds.109 Ds.109 - 1 year ago 126
Vb.net Question

Simple get initials from string - Visual Basic

Simple beginner exercise:

There's an input box where you put in your name seperated by spaces, then get the first letter from the first and last name and out put it to a label

I.e (Joe Bob) = JB

I know this could be done with an array, but the exercise is more to using string functions like substring, IndexOf, Remove, Replace etc...

Answer Source

You can try using the SubString and Split Methods.

 Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    Dim myInitials As String
    Dim myName As String = "Joe Bob"
    myInitials = myName.Substring(0, 1) & myName.Split(" ")(1).Substring(0, 1)
End Sub