IE and string.split('\n') - Javascript
This is a discussion on IE and string.split('\n') - Javascript ; 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 = ...
-
IE and string.split('\n')
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[i].length>longuest) ? thelines[i].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?
-
Re: IE and string.split('\n')
On May 29, 5:24 pm, noagbodjivic...@ wrote:
> 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[i].length>longuest) ? thelines[i].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)
-
Re: IE and string.split('\n')
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?
-
Re: IE and string.split('\n')
noagbodjivictor@ 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,':');
--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
-
Re: IE and string.split('\n')
noagbodjivictor@ 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)
--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Similar Threads
-
By Application Development in forum Python
Replies: 7
Last Post: 12-06-2007, 02:38 AM
-
By Application Development in forum Python
Replies: 12
Last Post: 11-30-2007, 05:04 PM
-
By Application Development in forum DOTNET
Replies: 0
Last Post: 05-14-2007, 11:17 AM
-
By Application Development in forum DOTNET
Replies: 2
Last Post: 04-12-2007, 10:06 AM
-
By Application Development in forum Inetserver
Replies: 10
Last Post: 02-08-2007, 04:19 PM