Adjit Adjit - 3 months ago 19
C# Question

Split string and exclude last split

Is there anyway for me to split a string and exclude the last split?

My data looks like this:

and so if I split the element the last element in the array will be empty, so I would just prefer to exclude it from the split.

Right now I have this:

serialNumbers = delimittedSerials.ToString().Split(',');

Granted I know I can just leave it and in my
loop just know to skip the last element, but was wondering if there was a simple way to just exclude it at the time of splitting.


you can split it using the StringSplitOptions parameter:

data.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);