...

View Full Version : string.replace() - bleh.



wyrd33
05-04-2006, 07:45 PM
If I do a string.replace("&lt;", "<"); it replaces the first instance of &lt; in the string. I want all instances of &lt; replaced, so I did string.replace("/&lt;/g", "<");. Unfortunately it now replaces none at all.

What's wrong with string.replace("/&lt;/g", "<");?

Beagle
05-04-2006, 07:52 PM
string.replace(/&lt;/g, "<");

you're using a string instead of a regular expression. Take the quotes out as in the above example

wyrd33
05-04-2006, 07:59 PM
string.replace(/&lt;/g, "<");

you're using a string instead of a regular expression. Take the quotes out as in the above example


Gah.. "duh" lol. Thanks. I guess my mind was stuck in PHP mode. :P

Kor
05-04-2006, 08:18 PM
I should have used rather unicode escapes to be able to safely handle the string within javascript:

string.replace(/&lt;/g,'\u003C');



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum