Reputation: 59
I have spilt one value in an array into 3 different values in a new array.
string [] names = new string[2];
names = oldcolumns[0].Split(' ');
I now want to be able to join names[1] and names[2] together. I have tried several different ways and cant seem to get it working.
This is an example of what I have tried
output = String.Concat(names[1], names[2]);
Upvotes: 0
Views: 70
Reputation: 48558
How about
output = String.Join(" ", new String[]{names[1], names[2]});
Upvotes: 0
Reputation: 101680
This can be done in one statement, using string.Join
var result = string.Join(" ", oldcolumns[0].Split(' ').Skip(1));
Upvotes: 1
Reputation: 61351
You could use string.Format
output = String.Format("{0} {1}",names[1], names[2]);
Upvotes: 0
Reputation: 4737
string[] names = "Mr James Bond".Split(' ');
string output = names[1] + " " + names[2];
Console.WriteLine(output);
Output: James Bond
Upvotes: 2