JavaScript Split string on blank lines split string blank space java,split string blank space c#,

I like to use Javascript's split method to split a string like the one below into an array on every blank white line.

How can I accomplish this. Splitting on \n doesn't because I'd like each paragraph to occupy just one element of the array and there are multiple \n's in each paragraph.

Any help will be greatly appreciated!

String:

CHAPTER TWENTY-ONE. MARIE'S SIDE OF IT

CHAPTER TWENTY-TWO. THE CURE COMPLETE



CHAPTER ONE. THE FEVER MANIFESTS ITSELF

There is a certain malady of the mind induced by too much of one
thing. Just as the body fed too long upon meat becomes a prey to that
horrid disease called scurvy, so the mind fed too long upon monotony
succumbs to the insidious mental ailment which the West calls "cabin
fever." True, it parades under different names, according to
circumstances and caste. You may be afflicted in a palace and call it
ennui, and it may drive you to commit peccadillos and indiscretions of
various sorts. You may be attacked in a middle-class apartment house, and
call it various names, and it may drive you to cafe life and affinities
and alimony. You may have it wherever you are shunted into a backwater of
life, and lose the sense of being borne along in the full current of
progress. Be sure that it will make you abnormally sensitive to little
things; irritable where once you were amiable; glum where once you went
whistling about your work and your play. It is the crystallizer of
character, the acid test of friendship, the final seal set upon enmity.
It will betray your little, hidden weaknesses, cut and polish your
undiscovered virtues, reveal you in all your glory or your vileness to
your companions in exile--if so be you have any.

If you would test the soul of a friend, take him into the wilderness
and rub elbows with him for five months! One of three things will surely
happen: You will hate each other afterward with that enlightened hatred
which is seasoned with contempt; you will emerge with the contempt tinged
with a pitying toleration, or you will be close, unquestioning friends to
the last six feet of earth--and beyond. All these things will cabin fever
do, and more. It has committed murder, many's the time. It has driven men
crazy. It has warped and distorted character out of all semblance to its
former self. It has sweetened love and killed love. There is an
antidote--but I am going to let you find the antidote somewhere in the
story.
Answer:1

Try something like this:

var paragraphs = text
    .replace(/\n\r/g, "\n")
    .replace(/\r/g, "\n")
    .split(/\n{2,}/g);

On Windows:

var paragraphs = text.split(/(\n\r){2,}/g);

On Linux:

var paragraphs = text.split(/\n{2,}/g);

On Mac:

var paragraphs = text.split(/\r{2,}/g);
Answer:2

Assuming there is a line break in between each paragraph, just split with '\n\n'.

var paragraphs = text.split('\n\n');

EDIT:

In this case, the source of the text at https://raw.githubusercontent.com/NinjaBanjo/synonym-search/master/out/w00020.html split lines using '&#xd', or carriage return. After getting this text and splitting it with text.split('
\n
'), the array is the right size. Working example at http://jsfiddle.net/cuVdE/211/.

Answer:3

I have an object game = {}; and I save an array with two id's under every number of the object - game[number] = [id1, id2]; e.g. game[0] = [234342, 134313]. How can I get the number of the object game[...

I have an object game = {}; and I save an array with two id's under every number of the object - game[number] = [id1, id2]; e.g. game[0] = [234342, 134313]. How can I get the number of the object game[...

  1. array object value javascript
  2. array object values
  3. array object value php
  4. array object values java
  5. object array values c#
  6. array value object required
  7. object array value filter
  8. get array object value in javascript
  9. change array object value javascript
  10. array object find value javascript
  11. sum array object values javascript
  12. array object get value
  13. array object key value javascript
  14. get array object value in php
  15. array includes object value
  16. array object find value
  17. update array object value javascript
  18. array object change value
  19. array object key value
  20. javascript array object value exist

I'm building a large AngularJS application in which some of the UI text needs to be content managed. This is because items such as contextual help will need to be edited by the client after launch in ...

I'm building a large AngularJS application in which some of the UI text needs to be content managed. This is because items such as contextual help will need to be edited by the client after launch in ...

  1. content management string

I have a list var jsonList = [ { "id": "one", "pId": "nosearch", "cId": "searchc" }, { "id": "two", "pId": "product1", "cId": "searchc" }, { "...

I have a list var jsonList = [ { "id": "one", "pId": "nosearch", "cId": "searchc" }, { "id": "two", "pId": "product1", "cId": "searchc" }, { "...

  1. json list filter
  2. json list filter jquery
  3. json list filter angularjs
  4. python json list filter
  5. javascript json list filter
  6. json drop down list filter
  7. filter json list angular

I'm working on an AngulaJS project and using the Bootstrap UI Modal window component. To close a Modal window, most examples use the following line of code: $uibModalInstance.dismiss('cancel'); I ...

I'm working on an AngulaJS project and using the Bootstrap UI Modal window component. To close a Modal window, most examples use the following line of code: $uibModalInstance.dismiss('cancel'); I ...

  1. what possible values of resultant resistance
  2. what possible values
  3. what are possible values for quantum numbers
  4. what are the possible values of remainder r
  5. what are the possible values of l for this orbital
  6. what are the possible values of ms for the orbital
  7. what are the possible values of quality gates in sonar
  8. what are the possible values of the magnetic quantum number