user123456789 user123456789 - 1 year ago 126
ASP.NET (C#) Question

Split string into two separate strings

I have a name that is just one string for example "LUKE CARROLL" and I want to split this string into first name and last name. So I just need to split the string where there is a space.

So I would end up with something like:

string FirstName = "Luke";
string LastName = "Carroll";

How do I do this?

Answer Source

Use split()

    string name= "LUKE CARROLL";
    string[] tmp = name.Split(' ');
    string FirstName = tmp [0]; 
    string LastName = tmp [1];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download