I have a string with 3 names(example: string name="Hunter Georgie Martin"). I have 3 tasks for that string:
- remove the first name
- remove the second name
- remove the third name
They don't depend on each other, meaning when deleting first name for the first task it shouldn't also be removed when doing the other tasks.
I completed the first task:
string name = "Hunter Gregorie Martin";//example
string str = name.Substring(name.IndexOf(' ')+1);
Console.WriteLine(str);
The output is what it should be: Gregorie Martin
The problem is that I can't think of a way to finish the other tasks in a similar way.
indexOf. You can get the second " " with the overload that takes a start-index. Then you basically have all you need. 1: First index+1 to end, 2: start to 1st index + 2nd index+1 to end, and 3: start to second index.string.Split(' ')might help you. But more generally, names are not a solved problem, and in fact are extremely difficult to get right.