-3

How to split the .text() , so that i should get new lines.

For suppose i have like this.

var loa = $('.loa_div').text();
alert(loa);

alert loa gives me,

Resultabc.resultdefgh.Resultkijklm.result12.Result888.kkkresult.123result.

I should get

Resultabc.    
resultdefgh.
Resultkijklm.
result12.
Result888.
kkkresult.
123result.
user3778091
  • 3
  • 1
  • 4

2 Answers2

2

Do you mean split like below?

var loa = $('.loa_div').text();
alert(loa.split(/(?=Result)/).join("\n")); // use <br> instead if you want to display as html.
xdazz
  • 158,678
  • 38
  • 247
  • 274
1
var str= "Resultabc.Resultdefgh.Resultkijklm.Result12.Result888";
var stresult=str.split('.').join('\n');

Demo:

http://jsfiddle.net/dp49Y/2/

RGS
  • 5,131
  • 6
  • 37
  • 65
  • Thanks... but i forgot to mention . not every line has Upper case.. then how do i do it? – user3778091 Jun 26 '14 at 07:10
  • @user3778091, Please show some other string. – RGS Jun 26 '14 at 07:12
  • To be even more specific I have something like this 'MK1 --- 08-06-2014 --- schedule missingMK1 --- 09-06-2014 --- schedule missing'. which will be in a single line one after the other. – user3778091 Jun 26 '14 at 07:15
  • ok for suppose i have '.' at the end of every result character. is it possible to split and switch to new line exactly after '.' ?? – user3778091 Jun 26 '14 at 07:23
  • @user3778091, I have updated my answer based on your feedback. Please check. – RGS Jun 26 '14 at 07:32