Results 1 to 6 of 6

Thread: Displaying the value of a Unicode character

  1. #1
    Join Date
    Dec 2009
    Posts
    192

    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.
    Last edited by Remedy; 26-02-2010 at 02:23 AM.

  2. #2
    Join Date
    Nov 2009
    Posts
    333

    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) );

  3. #3
    Join Date
    Nov 2008
    Posts
    240

    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

  4. #4
    Join Date
    Dec 2009
    Posts
    192

    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));
    
    }
    
    }

  5. #5
    Join Date
    Nov 2009
    Posts
    347

    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.

  6. #6
    Join Date
    Nov 2009
    Posts
    359

    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);
      }
    }

Similar Threads

  1. Replies: 2
    Last Post: 15-01-2012, 09:59 AM
  2. MS excel is not asking for CSV and Unicode (or UTF-8)
    By Kshama in forum Windows Software
    Replies: 5
    Last Post: 16-07-2011, 07:15 PM
  3. What is the unicode in PHP V5.3
    By Abigail101 in forum Software Development
    Replies: 5
    Last Post: 20-02-2010, 12:50 AM
  4. Regular expressions for unicode
    By Solaris in forum Software Development
    Replies: 4
    Last Post: 15-12-2009, 12:20 PM
  5. Conversion from Unicode to Hindi
    By D_chapple in forum Software Development
    Replies: 4
    Last Post: 28-11-2009, 06:48 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,888,489.25714 seconds with 17 queries