Ali
Ali

Reputation: 3615

How do you split elements in an array and return it as a new array

I have a array of string in following format.

string[] sports = { "Cricket" ,  "Football"  ,"Boxing/Tennis " , "Soccer"} ;

Is there any built in way in C# or using LINQ to split strings in array and return new array like

string[] sportsNewArray = { "Cricket" ,  "Football"  ,"Boxing" , "Tenis " , "Soccer"} ;

Upvotes: 1

Views: 1712

Answers (1)

Adrian Iftode
Adrian Iftode

Reputation: 15663

string[] sportsNewArray = sports.SelectMany(s=>s.Split('/')).ToArray();

Upvotes: 11

Related Questions