var testString = 'Sr No\tMonth\tMill\tOrigin\tParty\tOrder Date\t"Order Comp.\nDt."\n57\tJan-19\tGINZA\tIND\tSBL\t28.01.2019\t10.02.2019';
var newLine = testString.split('\n');
Oputput of the newLine
[ 'Sr No\tMonth\tMill\tOrigin\tParty\tOrder Date\t"Order Comp.','Dt."','57\tJan-19\tGINZA\tIND\tSBL\t28.01.2019\t10.02.2019' ]
在这里,当“Order Comp.\nDt.”
采用字符串形式时,我想避免使用\n
[ 'Sr No\tMonth\tMill\tOrigin\tParty\tOrder Date\t"Order Comp.\nDt."','57\tJan-19\tGINZA\tIND\tSBL\t28.01.2019\t10.02.2019' ]
最佳答案
那么为什么不匹配您想要保留的部分,而不是分割字符串呢?
var testString = 'Sr No\tMonth\tMill\tOrigin\tParty\tOrder Date\t"Order Comp.\nDt."\n57\tJan-19\tGINZA\tIND\tSBL\t28.01.2019\t10.02.2019';
var out = testString.match(/(?:"[^"]*"|[^\n])+/g);
console.log(out);
关于javascript - 使用避免 "\n"JavaScript 进行字符串分割,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54943212/