Solved

Ascii to unicode

Posted on 2004-10-22
1,585 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
Question by:Jerry_Pang
    2 Comments
     
    LVL 31

    Accepted Solution

    by:
    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
    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: MongoDB Object-Document Mapper for NodeJS

    NodeJS (JavaScript on the server) is awesome, but some developers get confused about NoSQL when it comes to working in Node with MongoDB (NoSQL database). Do you need a better explanation of how to use Node.js with MongoDB? The most popular choice is the Mongoose library.

    JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
    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.
    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…

    846 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

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now