IE and string.split('\n')

N

noagbodjivictor

IE6 refuses to split my text at '\n'. It acts like there is no
newlines at, while the script is working finely in FF.

var thetext = $$('#thetable tr td.textarea')
[0].childNodes[0].data;
var thelines = new Array();

thetext.replace(/\n/,':');
alert(thetext);
thelines = thetext.split(':');
alert(thelines[0]);
var longuest = thelines[0].length;
for(var i = 0; i < thelines.length; i++){
longuest = (thelines.length>longuest) ? thelines.length :
longuest;
}

I have placed those alerts to see what's happening. The text is:

The files in this directory are necessary for GVim Portable to
function.
There is normally no need to directly access or alter any of
the files
within these directories.

Do you have an idea?
 
D

Darko

IE6 refuses to split my text at '\n'. It acts like there is no
newlines at, while the script is working finely in FF.

var thetext = $$('#thetable tr td.textarea')
[0].childNodes[0].data;
var thelines = new Array();

thetext.replace(/\n/,':');
alert(thetext);
thelines = thetext.split(':');
alert(thelines[0]);
var longuest = thelines[0].length;
for(var i = 0; i < thelines.length; i++){
longuest = (thelines.length>longuest) ? thelines.length :
longuest;
}

I have placed those alerts to see what's happening. The text is:

The files in this directory are necessary for GVim Portable to
function.
There is normally no need to directly access or alter any of
the files
within these directories.

Do you have an idea?


Try thetext.replace(/\n/g,':'); (with the 'g' appended after the final
slash)
 
N

noagbodjivictor

It does not work. But.

"ohe\nohe".split('\n'); /* gives the correct answer */

The problem, then, comes from the text source. It's a a <td> styled
with { white-space: pre; }
Do you have any idea?
 
A

ASM

(e-mail address removed) a écrit :
IE6 refuses to split my text at '\n'. It acts like there is no
newlines at, while the script is working finely in FF.

var thetext = $$('#thetable tr td.textarea')
[0].childNodes[0].data;
var thelines = new Array();

thetext.replace(/\n/,':');

at least :

thetext.replace(/\n/g,':');

perhaps :

thetext.replace(/(\n|\r|\n\r)/g,':');

better ? :

thetext.replace(/\s/g,':');
 
A

ASM

(e-mail address removed) a écrit :
It does not work. But.

"ohe\nohe".split('\n'); /* gives the correct answer */


var txt = document.getElementById('myTd').innerHTML;
txt = txt.replace(/\s/g,'\n');
alert(txt.split('\n'));

(not tested)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top