所以,我有一个远程检索的文本文件,我想分裂两个换行符(\ n)字符。例如,受欢迎的赞美诗All Things Bright And Beautiful。奇怪的JavaScript新行分裂行为
All Things Bright And Beautiful
Cecil F. Alexander
All things bright and beautiful,
All creatures great and small,
All things wise and wonderful,
The Lord God made them all.
Each little flower that opens,
Each little bird that sings,
He made their glowing colours,
He made their tiny wings.
The purple-headed mountain,
The river running by,
The sunset and the morning,
That brightens up the sky;
The cold wind in the winter,
The pleasant summer sun,
The ripe fruits in the garden,
He made them every one;
The tall trees in the greenwood,
The meadows for our play,
The rushes by the water,
To gather every day;
He gave us eyes to see them,
And lips that we might tell
How great is God Almighty,
Who has made all things well.
看看TextMate与invisibles上显示我在诗句之间的两个换行符。到现在为止还挺好。当我复制并粘贴到这个IRB一切工作绝对没问题:
ruby-1.8.7-p334 :034 > content.split "\n\n"
=> ["All Things Bright And Beautiful\nCecil F. Alexander", "All things bright and beautiful,\nAll creatures great and small,\nAll things wise and wonderful,\nThe Lord God made them all. ", "Each little flower that opens,\nEach little bird that sings,\nHe made their glowing colours,\nHe made their tiny wings.", "The purple-headed mountain,\nThe river running by,\nThe sunset and the morning,\nThat brightens up the sky;", "The cold wind in the winter,\nThe pleasant summer sun,\nThe ripe fruits in the garden,\nHe made them every one;", "The tall trees in the greenwood,\nThe meadows for our play,\nThe rushes by the water,\nTo gather every day;", "He gave us eyes to see them,\nAnd lips that we might tell\nHow great is God Almighty,\nWho has made all things well."]
ruby-1.8.7-p334 :035 >
的问题出现的那一刻,我去的JavaScript。在控制台:
如果我分裂由一个\ n它工作绝对没问题。我试过使用回车符,换行符,传递正则表达式作为分隔符,似乎没有任何工作。我只是无法揭开这种行为的神秘面纱。
任何帮助将得到彻底赞赏。
“回车” \ n ... “换行” \ r。 – Incognito
数据如何进入元素?也许有东西缩进HTML代码,导致'\ n \ n'变成'\ n \ n' – jpa
它确实有效:http://jsfiddle.net/7Xe7q/ c/p那里的诗,然后点击split。然后检查控制台。 –