Link to home
Start Free TrialLog in
Avatar of java_casanova
java_casanova

asked on

Converting Unicode letter to its code

I want to know how do I convert any string having any Unicode character to UTF8 format in javascript? i,e if I want to convert the "météorologie" to "m&eacutet&eacuteorologie".

If you notice, u will find that the Unicode letter "é" is replaced with its code "&eacute".
ASKER CERTIFIED SOLUTION
Avatar of Pawel Witkowski
Pawel Witkowski
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Use escape() with replace and some regex.

Try the code below.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
<head> 
<title>Demo</title> 
</head> 
<body> 

<script type="text/javascript">

var u = 'météorologie';
u=escape(u).replace(/%(..)/g,"&#x$1;")

document.write(u);
alert(u);

</script>
</body> 
</html>

Open in new window

This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.