• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

UTF-8 & UTF-16 Format

 
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a problem to print string value in utf-8 format. The Given below function produce following outputs.

String out="Raghu";
System.out.println (new String(out.getBytes("utf-16"),"UTF-8")); gives ??
System.out.println (new String(out.getBytes("utf-16"),"UTF-16")); gives aRhg
System.out.println (new String(out.getBytes("utf-8"),"UTF-16")); gives ??

My problem is how to convert string values in utf-8 to utf-16 and utf-16 to utf-8. Could any one enlighten me?
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
from what i know in basic encoding/decoding of data(though i suggest u verify this),the encoding and decoding ends should share the same protocol; that means both should use the same scheme.

thus, when u encode with "UTF-8", i think it is advisable to decode with "UTF-8".same goes for "utf-16".

try this:
....
System.out.println(new String(out.getBytes("utf-8"),"utf-8");
OR
System.out.println(new String(out.getBytes("utf-16"),"utf-16");
[ June 24, 2005: Message edited by: henry akoma ]
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In addition, if you're looking at the output in a terminal window, the terminal may not understand Unicode, and thus be unable to display it properly. In that case, write the output to a file and look at the result in a Uniode-capable editor.
 
You ought to ventilate your mind and let the cobwebs out of it. Use this cup to catch the tiny ads:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic