简体   繁体   中英

Split a string using as separator all characters between two parenthesis in C#

I need to split a string in this form

[delimA][delimB]\n1delimA2delimB3

for example if I have

[***][%]\n1***2%3

it should return an array of

1 2 3

How can I do this?

You don't need a regular expression for this. String.Split can accept multiple delimiters, eg :

var line="[***][%%]";
var parts=.Split(new[]{'[',']'},StringSplitOptions.RemoveEmptyEntries);

StringSplitOptions.RemoveEmptyEntries as the name explains, will remove any empty entries after splitting

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM