How to cut off string after the first line in the paragraph

Zhen picture Zhen · Dec 8, 2011 · Viewed 51.7k times · Source

I have the string as show below:

XXX:Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur cursus lacus sed
justo faucibus id pellentesque nunc porttitor. Sed venenatis tempor dui, nec mattis dolor
ultrices at. Duis suscipit, dolor sed fringilla interdum, magna libero tempor quam, sed
molestie dui urna sed tellus.

How can I add a restriction and cut the string off at the first line? (using javascript).

The end result I would expect is as follows:

XXX:Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur...

Answer

Tomalak picture Tomalak · Dec 8, 2011
var firstLine = theString.split('\n')[0];