[英]javascript new line split is splitting at every n char
i am using below code to split the data but unfortunately not able to achieve it. 我正在使用下面的代码来拆分数据,但不幸的是无法实现它。
i have tried below things 我已经尝试过下面的事情
var lines = data. split(/\r\n|\r|\n/g);
data string is "this is ended here
another line "
what is happening is it is returing like below 正在发生什么是像下面这样重播
this is e
ded herea
other li
e
actually it is splitting at every character "n" i am going crazy.. but not able to find out what is issue. 实际上,它在每个字符“ n”处都在分裂,我要疯了..但无法找出问题所在。
could anybody please share some light on it. 有人可以分享一下它吗?
UPDATE - 更新-
i think something is wrong when i put it on godaddy hosting.. on my desktop it is working fine.. any idea?? 我认为将其放在Godaddy主机上时出了点问题。在我的桌面上,它工作正常。 This is server site javascript.
这是服务器站点javascript。
thank you 谢谢
UPDATE - 20/08/13 Despite various try my server level javascript split did not work, so i moved server level javascript to client level... and everything is working fine... 更新-20/08/13尽管进行了各种尝试,但我的服务器级javascript拆分未起作用,所以我将服务器级javascript移到了客户端级...并且一切正常。
Thank you everyone for answering this issue. 谢谢大家回答这个问题。 here i can accept only one answer as correct.. though all the answers provided below are correct.
在这里,我只能接受一个正确的答案。尽管下面提供的所有答案都是正确的。
Your regex must be wrong and you have written 您的正则表达式必须是错误的,并且您已经写了
split(/\n\r|\r|n/);
or something instead of 或什么代替
split(/\n\r|\r|\n/);
This code works for me in Chrome and FF : 这段代码在Chrome和FF中对我有用:
var data = "this is ended here \n another line ";
var lines = data.split(/\\r\\n|\\r|\\n/g);
console.log(lines);
It writes : 它写道:
["this is ended here ", " another line "]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.