all groups > dotnet jscript > march 2006 >
You're in the

dotnet jscript

group:

Converting special characters


Converting special characters quindo NO[at]SPAM gmail.com
3/23/2006 2:32:34 AM
dotnet jscript:
Hello,

I'm searching for a function in jscript to convert a special character
(like an o with an umlaut) to its html-code equivalent (ö).

Is there a function like that in Jscript?

Greetings,
Pieter
Re: Converting special characters Martin Honnen
3/29/2006 2:28:47 PM


[quoted text, click to view]

You can implement one

String.prototype.htmlEncode = function () {
return this.replace(/./g, function (c) { return '&#' + c.charCodeAt()
+ ';'; });
}

var s = 'ö';
s.htmlEncode()

if you want. Note that the above escapes any character, you might want
to change that depending on which characters you regard as 'special'.

And passing a function to the replace method is not supported in JScript
5 but only with JScript 5.5 and later.



--

Martin Honnen --- MVP XML
AddThis Social Bookmark Button