Converting Environment.UserName into initials

deanlee17
deanlee17 used Ask the Experts™
on
Hi Experts,

If the Environment.UserName gives me john.smith how can I get just the initials in upper case? i.e JS

Many Thanks.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Full stack Software Engineer
Commented:
Dim str = Environment.UserName.ToUpper()
Dim tokens = str.Split("."C)
Dim initials = String.Format("{0}{1}", tokens(0)(0), tokens(1)(0))

Open in new window

Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009

Commented:
You could also do something like:
    Private Function GetInitials() As String
        Dim Initials As String = ""
        Dim values() As String = Environment.UserName.Trim.ToUpper.Split(" .".ToCharArray) ' split on space " " and period "."
        For Each value As String In values
            Initials = Initials & value.Substring(0, 1)
        Next
        Return Initials
    End Function

Open in new window

Author

Commented:
Cheers guys. Both good methods. I will award the points to sedgwick as he replied first and im sure Idle_Mind wont mind :)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial