c# split string but keep split chars/ parameter
Today I came across a situ that I had to split a string based on ‘-‘ and keep the split char in the array as well.
Ex\ Split A-B-C-D to a string array with A,-,B,-,C,-,D
If I use the String.Split function with ‘-‘, it will only return the A,B,C,D without my split char.
So I decided to google, and I got nice long functions using regular expressions and substrings.
I didn’t want all those code in to do a simple thing like this and I went on cheating with Split function.
Number.Replace("-", ":-:").Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries)
so, am I cheating?