Reputation: 77
I'm looking to do something like this
public string[] getArray() {
string text = "1 ab cd 2 ef gh 3 ij kl 4 mn";
string[] arr = text.Split(" ").remove(every third element); //remove the 1,2,3,4 etc
return arr;
}
Upvotes: 2
Views: 421
Reputation: 52280
You can use Linq to skip every nth element.
public string[] getArray() {
string text = "1 ab cd 2 ef gh 3 ij kl 4 mn";
string[] arr = text.Split(" ").Where((x, i) => i % 3 != 0).ToArray();
return arr;
}
Upvotes: 2