Retrieve First Name and Last Name from string in asp.net

Retrieve First Name and Last Name from string in asp.net

VB.Net:

Dim name As String = “Joseph Van Andrews”

‘ Split string based on spaces
Dim names As String() = name.Split(New Char() {” “c})

‘ Seperate the first name from the rest of the string
Dim lastName as string = name.substring(names(0).length())

Dim nameString as string = “the First Name is: ” + names(0) + ” and the Last Name is: ” + lastName

response.write(nameString)

C#.Net:

string name = “ABC DEF XYZ”;

// Split string based on spaces
string[] names = name.Split(new char[] { ‘ ‘ });

// Seperate the first name from the rest of the string
string lastName = name.Substring(names[0].Length());

string nameString = “the First Name is: ” + names[0] + ” and the Last Name is: ” + lastName;

response.write(nameString);

Happy Coding πŸ™‚

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s