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".
java_casanovaAsked:
Who is Participating?
 
Pawel WitkowskiConnect With a Mentor Senior Javascript DeveloperCommented:
you need it unicode? Or just to send it via ascii ? you can use:

encodeURIComponent

and

decodeURIComponent


to make it using only ascii chars
0
 
hankknightCommented:
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

0
 
CWS (haripriya)Commented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.