Regex rx = new Regex(@"[+-]");
string[] substrings = rx.Split(expression);
expression = “-9a3dcbh-3bca-4ab4cf-3hc” //This is the iput string
I want to split that string between + or -.
My VS debugger shows substring array like this:
substrings[0] = null //???Why
substrings[1] = 9a3dcbh
substrings[2] = 3bca
substrings[3] = 4ab4cf
substrings[4] = 3hc
Why is the first element of arry null, is it because I am matching +-, and there is no + in my input string?
Because split eliminates the delimiter, and returns the string before and after the delimiters, in this case there are no characters before the delimiter, thus the first value is the empty string.