?
Solved

Converting Unicode letter to its code

Posted on 2009-04-29
4
Medium Priority
?
547 Views
Last Modified: 2012-05-06
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".
0
Comment
Question by:java_casanova
3 Comments
 
LVL 18

Accepted Solution

by:
Pawel Witkowski earned 1000 total points
ID: 24262199
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
 
LVL 16

Expert Comment

by:hankknight
ID: 26453804
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
 
LVL 16

Expert Comment

by:CWS (haripriya)
ID: 37187456
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question