Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.help > #1858

Re: Actual width of unicode chracters.

From Lew <lewbloch@gmail.com>
Newsgroups comp.lang.java.help
Subject Re: Actual width of unicode chracters.
Date 2012-06-13 14:14 -0700
Organization http://groups.google.com
Message-ID <ac90eba4-9efe-4c35-9f2b-2590326f1fe5@googlegroups.com> (permalink)
References <jr8tid$64v$1@tnews.hananet.net> <jr92cs$9m1$1@dont-email.me> <jr9h8n$ark$1@dont-email.me> <jr9j3p$qg0$1@tnews.hananet.net>

Show all headers | View raw


Young wrote:
> markspace wrote:
>> markspace wrote:
>>> String korean = ...
>>> int count = korean.codePointCount( 0, korean.length()-1 );
>> 
>>> A short, self-contained, compilable example would help here:
>>> http://sscce.org/
>> 
>> 
>> An SSCCE helps a lot!  I was wrong about the -1 to length(), it should
>> just be length().  The following seems to work for me.  If you have some
>> different idea, please write a code example so we can tell what you
>> mean.
>> 
>> 
>> 
>> package quicktest;
>> 
>> import javax.swing.JFrame;
>> import javax.swing.JTextArea;
>> import javax.swing.SwingUtilities;
>> 
>> /**
>>   *
>>   * @author Brenden
>>   */
>> public class Cjk {
>> 
>>     public static void main(String[] args) {
>>        SwingUtilities.invokeLater(new Runnable() {
>> 
>>           public void run() {
>>              createGui();
>>           }
>>        });
>>     }
>> 
>>     private static void createGui() {
>>        JFrame frame = new JFrame();
>> 
>>        int[] korChars = new int[10];
>>        for (int i = 0; i < korChars.length; i++) {
>>           korChars[i] = 0xAC00+i;
>>        }
>>        String kor = "test: "+new String( korChars, 0, korChars.length );
>>        JTextArea ta = new JTextArea( kor );
>>        frame.add(ta);
>> 
>>        ta.append("\nCount: "+ kor.codePointCount(0, kor.length() ));
>> 
>>        frame.pack();
>>        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
>>        frame.setLocationRelativeTo(null);
>>        frame.setVisible(true);
>>     }
>> }
> 
>   Thank you for the tries, I don't understand why I should use 
> codePointCount() method. The length() method gives same result. I want to 

Not in general it doesn't.

Read the Javadocs for the two methods and you'll see why.

> know how many literal spaces in console. Since Korean letter takes two 
> literal spaces in console mode. The result would be 26 instead of 16. 
> Anyone knows what I am missing? Thanks

They've told you what you're missing. You're welcome.

-- 
Lew

Back to comp.lang.java.help | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Actual width of unicode chracters. Young <ycp101@gmail.com> - 2012-06-13 02:23 +0000
  Re: Actual width of unicode chracters. Roedy Green <see_website@mindprod.com.invalid> - 2012-06-12 20:42 -0700
  Re: Actual width of unicode chracters. markspace <-@.> - 2012-06-12 20:45 -0700
    Re: Actual width of unicode chracters. markspace <-@.> - 2012-06-13 00:58 -0700
      Re: Actual width of unicode chracters. Young <ycp101@gmail.com> - 2012-06-13 08:30 +0000
        Re: Actual width of unicode chracters. markspace <-@.> - 2012-06-13 08:45 -0700
        Re: Actual width of unicode chracters. Lew <lewbloch@gmail.com> - 2012-06-13 14:14 -0700
          Re: Actual width of unicode chracters. Steven Simpson <ss@domain.invalid> - 2012-06-14 08:06 +0100
            Re: Actual width of unicode chracters. "mayeul.marguet" <mayeul.marguet@free.fr> - 2012-06-14 10:26 +0200
              Re: Actual width of unicode chracters. "Peter J. Holzer" <hjp-usenet2@hjp.at> - 2012-06-14 15:32 +0200
                Re: Actual width of unicode chracters. "mayeul.marguet" <mayeul.marguet@free.fr> - 2012-06-14 16:47 +0200
                Re: Actual width of unicode chracters. "Peter J. Holzer" <hjp-usenet2@hjp.at> - 2012-06-16 20:39 +0200
  Re: Actual width of unicode chracters. Joshua Cranmer <Pidgeot18@verizon.invalid> - 2012-06-13 00:00 -0400
  Re: Actual width of unicode chracters. markspace <-@.> - 2012-06-13 00:24 -0700
  Re: Actual width of unicode chracters. Steven Simpson <ss@domain.invalid> - 2012-06-13 10:24 +0100

csiph-web