-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?

3
  • Have you looked at string.Split Commented Dec 1, 2016 at 10:07
  • string[] parts = myString.Split(' ');? Commented Dec 1, 2016 at 10:07
  • 2
    Names are complex: Van der Graaf, Charles de Batz-Castelmore d'Artagnan Commented Dec 1, 2016 at 10:09

1 Answer 1

3

Use split()

    string name= "LUKE CARROLL";
    string[] tmp = name.Split(' ');
    string FirstName = tmp [0]; 
    string LastName = tmp [1];
Sign up to request clarification or add additional context in comments.

1 Comment

textbox2.text= tmp[0].SubString(0,tmp[0].Length-4).TrimStart('+').TrimStart('0');???

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.