-6

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?

user123456789
  • 1,914
  • 7
  • 44
  • 100

1 Answers1

3

Use split()

    string name= "LUKE CARROLL";
    string[] tmp = name.Split(' ');
    string FirstName = tmp [0]; 
    string LastName = tmp [1];
Lucifer
  • 1,594
  • 2
  • 18
  • 32
  • 3
    `textbox2.text= tmp[0].SubString(0,tmp[0].Length-4).TrimStart('+').TrimStart('0');`??? – Pikoh Dec 01 '16 at 10:11