Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Ascii to unicode

Posted on 2004-10-22
2
Medium Priority
?
1,603 Views
Last Modified: 2008-02-01
<script type="text/javascript">

Function ascii2unicode(text)
{
unicode= text
return unicode
}
</script>

=)

i want to convert the text to \u???? characters. (A points)

if thats possible. or replace any characters > 127 to "?"(B points) - (assited)

Having problem with unicode characters submmiting to my active x on a different language setings.
i figured i will need a javascript program that will convert any chinese/ñ special characters (ascii >127) to a ? character or convert it to a unicode text then my active x is good to go..

thanx. need info how
0
Comment
Question by:Jerry_Pang
[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 Comments
 
LVL 31

Accepted Solution

by:
GwynforWeb earned 2000 total points
ID: 12387282
this perhaps?

<script>
function hexVal(char){
  decNum=char.charCodeAt(0)
  if ( decNum>127 ){
    hex=decNum.toString(16).toUpperCase();
   switch (hex.length){
    case 2:hex='\\u'+'00'+hex
      return hex
    case 3:hex='\\u'+'0'+hex
      return hex
    default :
      return '\\u'+hex
   }
 }
 else
  return char
}

function convert(str){
 result=''
 for (i=0;i<str.length;i++)
   result+=hexVal(str.charAt(i))
 return result
}
</script>


<input name="t1" size="50">input string<p>
<input value="convert" type="button" onclick="alert(convert(t1.value))">

0
 
LVL 9

Author Comment

by:Jerry_Pang
ID: 12417690
this is what i need
thanx. just posting it here for my history questions.

function hexVal(char){
  decNum=char.charCodeAt(0)
  if ( decNum>127 ){
    hex=decNum.toString(10).toUpperCase();
   switch (hex.length){
    case 2:hex='&#'+'00'+hex + ';'
      return hex
    case 3:hex='&#'+'0'+hex + ';'
      return hex
    default :
      return '&#'+hex + ';'
   }
 }
 else
  return char
}
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
This article discusses how to implement server side field validation and display customized error messages to the client.
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…

597 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