Need to get first letter of a a user's first name using vb.net.

Hi,
What I need to do is get the first letter of a user's First name.  For example;  If the user's name is John Smith, then I would need just "J".  I'm using this to create user names for our active directory online web form.  I need the first letter of the user's first name and then add the last name.  So John Smith would be "JSmith".  How can I do this using vb.net. I know there are variious ways around this.
Thank you,
Kouts1
kouts1Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
xoperatorConnect With a Mentor Commented:
If you need anything else tell me.
0
 
xoperatorCommented:
Hi,

You can use this article to manipulate strings in vb.net:

http://www.vbdotnetheaven.com/Uploadfile/mahesh/StringsinDotnet04212005074227AM/StringsinDotnet.aspx

Enjoy :)
0
 
GMGeniusCommented:
Simple
        Dim sUserName As String = "GMGenius"
        Dim sUserInitial As String = sUserName.Substring(0, 1)

Open in new window

0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
hesConnect With a Mentor Commented:
Try something like this (not error checked) Not sure how ou are getting the user name but in this example I assign it to a string variable
        Dim strFullUserName As String = "John Smith"  'Get username in variable
        Dim strArrayName() As String = strFullUserName.Split(" ") ' split on a space
        Dim strYourName As String = String.Concat(strArrayName(0).Substring(0, 1), strArrayName(1)) 'Concatenate parts
        MessageBox.Show(strYourName)




0
 
GMGeniusConnect With a Mentor Commented:
Actually better still

This will deal with Middle names
        Dim sUserName As String = "John Smith"
        Dim sArrayName() As String = sUserName.Split(" ") ' split on a space
        Dim sYourName As String = String.Concat(sArrayName(0).Substring(0, 1), sArrayName(sArrayName.Length - 1))

Open in new window

0
 
masterpassConnect With a Mentor Commented:
Try this too
Dim Name As String = "John Smith"
Dim Names As String() = Name.Split(" "c)
Dim AdName As String = Names(0).Substring(0, 1) + Names(1)

Open in new window

0
All Courses

From novice to tech pro — start learning today.