5 Replies Latest reply: Nov 13, 2006 6:37 AM by 807607 RSS

    Unicode to hex conversion

    807607
      Hi friends,
      I have unicode string and in want to change it to hex representation. for e.g.
      String unicodemsg="इंजीनियर";

      I want to change it on the format as

      String hexmsg="\u0907\u0902\u091c\u0940\u0928\u093f\u092f\u0930";
      Please help me.
      Thanks and Regards
      Ram
        • 1. Re: Unicode to hex conversion
          800322
          Isn't it the same string this other guy asked about three days ago?
          • 2. Re: Unicode to hex conversion
            800322
            Hint: Integer.toHexString().
            • 3. Re: Unicode to hex conversion
              807607
              Thanks for reply
              I tried it as

              String unicode="इंजीनियर";
              char []a = unicode.toCharArray();
              for(int m = 0; m< a.length; m++)
              {
                                            String hex = new String(Integer.toHexString(a[m]));
                                            System.out.println("HEX :" + hex);
                                            message=message+"\\u0"+hex;
              }
                                            
              System.out.println("Unicoded message:"+message);

              and it prints the following results.
              \u0907\u0902\u091c\u0940\u0928\u093f\u092f\u0930

              But when i tried on another,it does not work.

              Help please
              • 4. Re: Unicode to hex conversion
                807607
                But when i tried on another,it does not work.
                another what ??

                In case you are dealing with some message properties file then its better to convert the native file to ascii using a native2ascii converter tool. Then you need not use Integer.toHexString(..)

                You can run the following command on DOS for convertion of a japanese file into unicode ..

                native2ascii message_jp.properties message_ja_JP.properties

                The system will then pick and read the messages from this unicode file.

                Native2ascii converts things to ASCII using Unicode escapes.

                Google for a free download for Native2ascii converter.

                -Rohit
                • 5. Re: Unicode to hex conversion
                  807607
                  Thanks again
                  but problem still exists.
                  In for loop , message variables is initialized with the following hex value.
                  message="\u0907\u0902\u91c\u0940\u0928\u093f\u092f\u0930";

                  when i submit this message to smsc , it is delivered to mobile phone but can't be read.

                  When i directly initialized message variable with the above hex value it is delivered properly. I am not getting what is wrong with the code.

                  Regards Ram

                  Message was edited by:
                  ram@1981