How can I split a string by '-'
and '>'
and not by "->"
?
I would like to split the string below:
AAA-BBB->CCC>DDD
and get the result equal to:
{ "AAA", "BBB->CCC", "DDD" }
How can I split a string by '-'
and '>'
and not by "->"
?
I would like to split the string below:
AAA-BBB->CCC>DDD
and get the result equal to:
{ "AAA", "BBB->CCC", "DDD" }
The following example uses a regular expression with lookahead and lookbehind rules to split a string based on '-' or '>' but not '->':
string input = "AAA-BBB->CCC>DDD";
var regex = new Regex("-(?!>)|(?<!-)>");
var split = regex.Split(input);
// split = { "AAA, "BBB->CCC", "DDD" }