Displaying the value of a Unicode character
Hello,
Here is my code
Code:
String str = new String ("?") ;
String stru = new String ( str.getBytes(), "UTF-8" );
DevoyellationArabe.getStrDevArabe(stru);
getStrDevArabe and function is as follows:
Public static String getStrDevArabe (String str){
if (str.charAt(0) == '?') {
System.out.System.out.println("B is correct +++++++++++++++++++");
} else {
System.out.System.out.println("This is not correct -----------------------");
}
System.out.print(str.charAt(0));
return null;
}
I am trying to display the Unicode character , but I think there is a problem with the code, here is the code.
Re: Displaying the value of a Unicode character
Hello,
The char is always a character and not the code that is displayed (Means that your console does not support this character). To display the value of its code should display it as a int :
Code:
System.out.System.out.println( (int)s.charAt(0) );
This gives you 1576 (base 10).
And for the unicode just convert in base 16, for example:
Code:
System.out.System.out.println( Integer.toHexString(s.charAt(0)) );
Display 628
Or with Java 5 and the method printf ():
Code:
System.out.printf( "% 04x", (int)s.charAt(0) );
Re: Displaying the value of a Unicode character
Hey guys
Even I had a similar kind of a problem some time back. I did as you told here but does not display what I want, knowing that the value of char is a character and Arab ن , if I change character the answer is always
Code:
char c = 'ن';
System.out.println ((int) char);
System.out.println (Integer.toHexString (char));
Any help on this. Please
Re: Displaying the value of a Unicode character
Hey
Here is code which I am trying to do
Code:
import java.io. *;
public class main (
public static void main (String [] args) throws UnsupportedEncodingException (
char char = '?';
System.out.println ((int) char);
System.out.println (Integer.toHexString (char));
System.out.println ("------------------------------");
ch char = '?';
System.out.println ((int) ch);
System.out.println (Integer.toHexString (ch));
}
}
Re: Displaying the value of a Unicode character
Hello,
Here is some more information on this
New line is \n
Tab is \t
Backspace is \b
Carriage return is \r
Formfeed is \f
Backslash is \\
Single quotation mark is \'
Double quotation mark is \d
Octal is \d
Hexadecimal is \xd
Unicode character is \ud
Hope this will help you.
Re: Displaying the value of a Unicode character
Hello,
Just have a look at the following example
Code:
public class Jst extends JPanel {
static JFrame frm;
public Jst() {
Vector ls = new Vector();
ls.add("\u00e4pple");
ls.add("banan");
ls.add("p\u00e4ron");
ls.add("orange");
// Obtain a Swedish collator
Collator cl = Collator.getInstance(new Locale("sv", ""));
Collections.sort(ls, cl);
StringBuffer rs = new StringBuffer();
for (int i = 0; i < ls.size(); i++) {
rs.append(ls.elementAt(i));
rs.append(" ");
}
add(new JLabel(rs.toString()));
}
public static void main(String s[]) {
Jst pn = new Jst();
frm = new JFrame("Jst");
frm.getContentPane().add("Center", pn);
frm.pack();
frm.setVisible(true);
}
}