[英]Splitting by \n character doesn't seem to work
I'm getting a result from a server where items are separated with new lines, so I do a: 我从服务器获取结果,其中项目用新行分隔,所以我做了一个:
split('\n');
split('\\n');
It doesn't work! 它不起作用! the
\\
disappears while debugging on Chrome (I see split('n')). 在Chrome上调试时,
\\
消失了(我看到split('n'))。
How to make it work? 如何使它工作?
Sample data (copy from debugger of chrome): 示例数据(从chrome调试器复制):
"יופי וקוסמטיקה|10↵בידור ותרבות|9↵לילד ולתינוק|3↵תיירות|4↵תכשיטים|5" “יופיוקוסמטיקה|10↵בידורותרבות|9↵לילדולתינוק|3↵תיירות|4↵תכשיטים| 5”
If the result has the literal characters "\\n"
in it, you need to escape your \\
. 如果结果中包含文字字符
"\\n"
,则需要转义\\
。
split('\\n');
Another possibility is that you have \\r\\n
sequences in the string. 另一种可能性是你在字符串中有
\\r\\n
序列。 If so, do this: 如果是,请执行以下操作:
split('\r\n');
...although the .split('\\n')
should still work. ...虽然
.split('\\n')
应该仍然有效。
Or if it is sending them with just \\r
sequences, you'd do: 或者如果它只用
\\r
序列发送它们,你会做:
split('\r');
If you're not sure, do this: 如果您不确定,请执行以下操作:
split(/\r\n|\n|\r/);
I tried it with split("\\n")
and it is working. 我用
split("\\n")
尝试了它,它正在工作。
The choice of double or single quotes will make a difference in the way that Ruby treats the contents. 选择双引号或单引号会对Ruby处理内容的方式产生影响。
if you have '↵' character in your paragraph, 如果你的段落中有'↵'字符,
Firstly you must replace '↵' character to '\\n' then 首先,您必须将'↵'字符替换为'\\ n'
and if you have web project 如果你有网络项目
you must use 'white-space: pre-line' in your css code. 你必须在你的css代码中使用'white-space:pre-line'。
I have some problem when I get paragraph from database paragraph coming with '↵' character and it not add new line in paragraph I used this solution for this problem. 当我从数据库段落中带有'↵'字符的段落并且它没有在第I段中添加新行时使用此解决方案来解决此问题时,我遇到了一些问题。
我在一个在模板引擎下运行的页面上工作,它从“ \\n
”中删除了“ \\
”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.