Solved

Convert NCR to javascript \u?

Posted on 2009-04-06
2
2,265 Views
Last Modified: 2012-05-06
Hi, I'm trying to convert text in "numerical character reference" format to javascript escape (\u) format.  for example 소개 should become \uC18C\uAC1C.

I need to do this conversion in a Javascript routine or PHP.

Any ideas?  I'm lost
kenw232@yahoo.com
0
Comment
Question by:scottg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24084601
If it is a string:



 <script>
 function d2h(d) {return d.toString(16).toUpperCase();}
 function ncr2utf(str) {
   var chars = str.replace(/\&\#/g,'').split(';')
   for (var i=0;i<chars.length;i++) if (chars[i]) chars[i]="\\u"+d2h(parseInt(chars[i]));
   return chars.join(''); 
 }
 document.write(ncr2utf("&#49548;&#44060;")) //  should become \uC18C\uAC1C.
 </script>

Open in new window

0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 500 total points
ID: 24084628
Clearer to see


 <script>
 function d2h(d) {return d.toString(16).toUpperCase();}
 function ncr2utf(str) {
   var chars = str.replace(/\&\#/g,'').split(';')
   for (var i=0;i<chars.length;i++) if (chars[i]) chars[i]="\\u"+d2h(parseInt(chars[i]));
   return chars.join(''); 
 }
 var str = "&#49548;&#44060;"
 document.write(str.replace(/&/g,'&amp;')+':['+str+']:['+ncr2utf(str)+']') //  should become \uC18C\uAC1C.
 </script>

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

749 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