I want something like:
"aaaXaaaXaaaXaaaYXaaa".Split('X');
but want it to ignore 'YX'.
Of course I can simply loop and correct for it. But is there a built-in method for that?
You can use a regular expression with a negative lookbehind:
string[] result = Regex.Split(s, "(?<!Y)X");
See it working online: ideone
More information about lookarounds: Lookahead and Lookbehind Zero-Width Assertions
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.