开发者

Multiple delimiters using Regex.Split in C#

开发者 https://www.devze.com 2023-01-01 22:25 出处:网络
Let\'s say you need to split a string 开发者_StackOverflow中文版by various delimiters including newline (/r, /n) and a few other \'special\' character strings.

Let's say you need to split a string 开发者_StackOverflow中文版by various delimiters including newline (/r, /n) and a few other 'special' character strings.

For example:

This is a sample %%% text &&& that I would 
like to split %%% into an array.

I would like the following in the resulting string array (contents via index)

[0]This is a sample
[1]text
[2]that I would
[3]like to split
[4]into an array.

I would like to use C# Regex.Split() function. What is the regex expression to match on all of my delimiters?

Thanks in advance


Just FYI, the vanilla String.Split() method has an overload which accepts an array of strings to use as delimiters. Here's a link to MSDN's page describing it.


%%%|&&& should do it.

0

精彩评论

暂无评论...
验证码 换一张
取 消