8

We are Developing phonegap application.We get Data form CSV file. It's look like this We getting data like this

We need Data Split into two strings Like
String1 enter image description here

String2 enter image description here

We tried like this but We don't have luck so Please guide me

var split = string.split('\r\n');

Please help me

Pavan Alapati
  • 267
  • 3
  • 5
  • 15

2 Answers2

11

try this:

var split = string.split(/\n/);
Victor Lin
  • 141
  • 2
4

Replace the new line characters with space and then split the string with space

string.replace( /\n/g, " " ).split(" ");

UPDATE:

var string1=string.substring(0,string.indexOf("TOTALAMOUNT"));
var string2=string.substring(string.indexOf("TOTALAMOUNT"),string.length);

Or if your string contains \n then:

var string1=string.substring(0,string.indexOf("\n"));
var string2=string.substring(string.indexOf("\n"),string.length);


alert(string1);
alert(string

Fiddle

Brijesh Bhatt
  • 3,810
  • 3
  • 18
  • 34
  • thanks for reply.We tried as you said var newstirng=string.replace( /\n/g, " " ).split(" "); alert(newstirng[0]); it's not come with first String Please guide me – Pavan Alapati Apr 10 '15 at 10:11
  • You can refer the fiddle .. http://jsfiddle.net/13h25soo/ .. and you give me your string then i can be able solve it.. @PavanAlapati – Brijesh Bhatt Apr 10 '15 at 10:20
  • we have data like this it's not String format ITEMS,DESCRIPTION,UMO,QTY,PRICE,lineamount,CUSTOMERID,TODAY DATE,ORDERID,BOOKORDER,FOC BODYLINE SUPER 20 G*10 DOZ,100MG,CTN,1,1093.55,1093.55,ARU011,2015-4-9,Himansu15:9:59059,ABCARU0119590,0 TOTALAMOUNT,DISCOUNT,NET AMOUNT,VAT,GROSS AMOUNT,BOOKORDER,CUSTOMERID,TODAYDATE 38426.87,1,38042.6,2,38803.45,ABCARU011959,ARU011,2015-4-9 – Pavan Alapati Apr 10 '15 at 10:38
  • Updated my answer.. check it i think it will help .. @PavanAlapati – Brijesh Bhatt Apr 10 '15 at 10:59