Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to split string using regex

I'd like to split a string with using pattern like this:

it starts and ends with '\n' and contains an arbitrary number of whitespace or '\n' in between.

Edit:

This input:

string s = "aaa\n    \nbbb\n    \nccc\n   \n   \nddd"; 

should result in an array containing

aaa
bbb
ccc
ddd
like image 790
Pedro Avatar asked Apr 22 '26 03:04

Pedro


1 Answers

Given your example, string.Split will be much cleaner.

var vals = s.Split('\n', StringSplitOptions.RemoveEmptyEntries);
like image 145
Austin Salonen Avatar answered Apr 24 '26 17:04

Austin Salonen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!