Unicode question

Hi all,

I am writing a program which generates an onscreen keyboard for typing various languages.

I take the name of the laguage as an argument and generate the appropriate keyboard using Unicode.

For this purpose, I have a list of the starting and ending unicode character for all the languages that I support.

Example:

private int start = 0x0C82;

private int end = 0x0CEF;

I need to know if there is a way in which I can generate all the unicode string literals between the start and end character?

If I try something like this,

ArrayList<String> unicodes = new ArrayList<String>;

String s;

for( int i=0 ; i<(end-start); i++) {

s = "\u"+start++;

unicodes.add(s);

}

I get the "illegal unicode escape" error. I also tried doind the same by appending the individual characters (\,u etc) to a StringBuffer, but that does not seem to work either.

Can anyone please let me know if there is a way this can be achieved?

Thanks in advance!

[1061 byte] By [pradeep@echa] at [2007-11-27 5:13:14]
# 1

The simplest way is to cast your integers to characters. An example is like this:

int start = 0x0031;

int end = 0x004F;

char c;

for (int i = start; i <= end; i++) {

c = (char) i;

System.out.print(c); // or do whatever you want with c

}

Be warned that Java is using Unicode UTF16, that means higher Unicode characters are represented by surrogate pairs. If you're to represent them, you need to do more code. For more info, look at:

http://java.sun.com/javase/6/docs/api/java/lang/Character.html

HTH

horiniusa at 2007-7-12 10:34:42 > top of Java-index,Desktop,I18N...
# 2
That solved my problem.Thanks a lot!
pradeep@echa at 2007-7-12 10:34:42 > top of Java-index,Desktop,I18N...