how to split text into paragraph?

Updated on August 27, 2017 in  [R] Scripts
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
6 on August 3, 2017

notepad file example

hello
hello
hello

good
good
good

morning
morning
morning

 

how to split this to 3 variables with one paragraph on each variable?

 

  • Liked by
Reply
5 on August 3, 2017

You can split the file every empty space (\n).

yourFile.Split ('\n');

That returns an array:

string [] paragraphs = yourFile.Split ('\n');

on August 8, 2017

that split per line so its gonna be

paragraphs[0] = hello, paragraphs[1] = hello , paragraphs[2] = hello , paragraphs[3] =  , paragraphs[4] = good

what i want is

paragraphs[0] = hello

                           hello

                           hello

paragraphs[1] = good

                          good

                          good

 

Devoted
on August 8, 2017

you could do

yourFile.Split ('\n\n');

and then that should work, so long as there aren’t any spaces on the blank line…

Devoted
on August 9, 2017

That wouldn’t work because .Split takes a character and \n\n are two characters.

Devoted
on August 16, 2017

Ah. Good point…

Then after splitting up by ‘/n’ you could check if the part is == “” then remove it from a list of the strings

on August 27, 2017

thanks for the answer

Show more replies
  • Liked by
Reply
Cancel