For starters, we will need to get the raw data. This being the raw user name data.
Dim rName As String = My.User.NameThis will return our unformatted string with the domain of the user such as "ComputerName\UserName"
We will now need to format our string to get the correct values.
Dim lSlash As Integer = rName.LastIndexOf("\")
Dim fName As String = rName.Substring(lSlash + 1)
In this case, we will be using String.LastIndexOf. We will then add one (1) to the lSlash integer to give us the correct user name. The string named fName now holds are user name.Your final code should look like this:
Dim rName As String = My.Computer.Name
Dim lSlash As Integer = rName.LastIndexOf("\")
Dim fName As String = rName.Substring(lSlash + 1)
MsgBox(fName)
I decided to show a message box with the logged on user's name. You can do whatever you would like with fName.











