facebook - Triming and creating a text ellipsis in Javascript based NOT on the number of characters but the number of line breaks -


I want to program a function that takes in some text and trim on the number of lines on it , I want to trim it and after the "... read more" it hits 6 line breaks, such as with Facebook comments and wall posts.

Thank you.

You can use the last index property of a global regular expression.

  var str = 'one \ ntwo \ nthree \ nfour \ nfive \ nxix \ n', rx = /((.+\n+){3})/g, m = rx Exec (str), cut = rx.lastIndex; If (cut) {first3lines = m [1] .replace (/ \ s + $ /, '...'); Balance = str. Spring (cut); } Else {first3lines = str; Balance = ''; } Alert ('first 3 rows: \ n' + 3links + '\ n \ n Finish: \ n' + left); / * Return value: first 3 rows: one two three ... remaining: four five six: * /    

Comments

Popular posts from this blog

qt - switch/case statement in C++ with a QString type -

python - sqlite3.OperationalError: near "REFERENCES": syntax error - foreign key creating -

Python's equivalent for Ruby's define_method? -