I know how to remove elements from an array if i know what they are.
The “client” in this array is an string input by the user. I want to remove the first 2 words, but I don’t know what they’ll be. Its always different.
string[] words = Receipt.Split(' ',',','-');
Thanks.
If you always want to remove the first two, LINQ probably provides the simplest approach:
Note that you can’t “remove” values from the array itself, as an array always has a fixed size after creation. The code above creates a new array with all but the first two words.
Of course, you can do it all in one go:
Personally I’d usually use a
List<string>instead, as it’s more flexible:If you’re just going to iterate over it, you don’t need to convert it to an array or a list at all: