WebFX WebBoard
Message Thread:
View All Messages
Back to WebFX
 Optimizing, mikael bergkvist, July 8, 2003
     Re:Optimizing, Erik Arvidsson, July 8, 2003

Subject: Re:Optimizing From: Erik Arvidsson Date: July 8, 2003
I guess you could use a "smart" replace.

var re = /(\&lt\;)|(\&gt\;)|(\=\")/g, f);
function f($0,$1,$2,$3) {
if ($1) return "<span style=\"color:red\">&lt;&lt;!&gt;";
if ($2() return ...
...
}
data = data.replace(re, f)

I do not know if this is faster but using replace like you are doing is not too fast. A better way is probably ot create a tokenizer and then a parser.

erik

_______________________________________________________

Is there a way to have the same job done faster?
for(var i=0;i < data.length/75;i++)
{
data=data.replace('&lt;','<font color=red><<!>');
data=data.replace('&gt;','<!>></font>');
data=data.replace('="','<font color=green>=</font>"');
data=data.replace('"','<font color=blue>&quot;');
data=data.replace('"','&quot;</font>');
}



Reply
Name: 
Email: 
Subject: 

Enter your reply to this message below. HTML tags are not supported but words that start with http://, ftp:// or mailto: are converted to links.


View All Messages
Back to WebFX