test <te**@test.test> writes:
On Wed, 19 Apr 2006 10:43:51 GMT, Noozer wrote:
"test" <te**@test.test> wrote in message
news:10******************************@40tude.net.. . Code:
a = document.createTextNode("< somestring >");
...will transform < into < and > into >
I think what you want is encode() and decode()...
a = encode("< somestring >");
...and...
a = decode("<%20somestring%20>");
But, there are no such functions in JavaScript? I can't find
them, and I get errors in javascript:
"encode is not defined"
I don't know them either.
But you can make a decoder relatively easily:
---
var conversionMap = {
"amp" : "&",
"lt" : "<",
"gt" : ">",
"apos" : "'",
"quot" : '"'
}
function decode(entityString) {
return entityString.replace(/&(\w+);/g, function(m,g) {
return conversionMap[g]||m;
});
}
---
It requires a modern browser that accepts a function as second a
argument to replace.
If your string contains URL-escapes (%xx), you can first decode
these using the global "unescape" function (or after, depending
on what you want to unescape first).
/L
--
Lasse Reichstein Nielsen -
lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'