c# - How to split string preserving spaces and any number of \n characters -


i want split string , create collection, following rules: string should splitted words.

1) if string contains '\n' should considered seperate '\n' word.
2) if string contains more 1 '\n' should considered more on '\n' words.
3) no space should removed string. exception is, if space comes between 2 \n can ignored.

ps: tried lot string split, first split-ted \n characters , created collection, downside is, if have 2 \n consecutively, i'm unable create 2 dummy words collection. appreciated.

enter image description here

is there anyway using regex?

split regex this:

(?<=[\s\n])(?=\s) 

something like:

var substrings = regex.split(input, @"(?<=[\s\n])(?=\s)"); 

this not remove spaces @ all, not required should fine.

if want spaces between \ns removed, split like:

(?<=[\s\n])(?=\s)(?:[ \t]+(?=\n))? 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -