user3734454
user3734454

Reputation: 59

how to join two out of three values of an array

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

Answers (4)

Nikhil Agrawal
Nikhil Agrawal

Reputation: 48558

How about

output  = String.Join(" ", new String[]{names[1], names[2]});

enter image description here

Upvotes: 0

Selman Genç
Selman Genç

Reputation: 101680

This can be done in one statement, using string.Join

var result = string.Join(" ", oldcolumns[0].Split(' ').Skip(1));

Upvotes: 1

Matas Vaitkevicius
Matas Vaitkevicius

Reputation: 61351

You could use string.Format

output = String.Format("{0} {1}",names[1], names[2]);

Upvotes: 0

Davio
Davio

Reputation: 4737

string[] names = "Mr James Bond".Split(' ');
string output = names[1] + " " + names[2];
Console.WriteLine(output);

Output: James Bond

Upvotes: 2

Related Questions