Changed behavior in RegEx.Split after updating .NET framework

The client updated their systems and they began to report errors on the output. Apparently, line splitting used to lead to the following.

"abc" -> {"a", "b", "c"} 

Now, however, they get it.

 "abc" -> {"a", "-", "b", "-", "c"} 

I checked intellisense, but as far as I can tell, there is no way to enable / disable the inclusion of delimiters. How can this be easily dealt with?

The best suggestion that I have on my head is to split with a regex, and then when it uses a link with a regex matching condition. It seems superfluous, though ...

The current version is 4.5. They used to have something ooold , like 2.0 or something like that.

+6
source share
1 answer

The behavior of .NET 4.5 is correct.

Capture group content is added to the split result. Therefore Regex.Split("abc", "(-)"); -)"); will add a dash to the array.

Use Regex.Split("abc", "-"); instead of this.

+3
source

Source: https://habr.com/ru/post/944820/


All Articles