wood burning stoves 2.0*
The moose likes Java in General and the fly likes Unicode characters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Unicode characters" Watch "Unicode characters" New topic
Author

Unicode characters

Jose Cao
Greenhorn

Joined: Nov 06, 2002
Posts: 5
Hi,
I have the following code:
//-----
1 public static String leer(BufferedReader sin) {
2 StringBuffer line = new StringBuffer();
3
4 try {
5
6 for (int ch; (ch = sin.read()) != 1; ){
7 line.append(ch);
8 }
9
10 } catch (IOException e) {
11 System.out.println("leer: " + e.toString());
12 }
13 if (linea != null)
14 System.out.println(line.substring(0));
15 return line.substring(0);
16 }
//-----
The problem is, at line 6, "sin.read()" returns a int (which is a unicode code) and I need the equivalent character to build a string. How can I obtain the character that corresponds to this unicode code?
Thanks in advance.
Ellen Zhao
Ranch Hand

Joined: Sep 17, 2002
Posts: 581
Originally posted by Jose Cao:
Hi,
I have the following code:
//-----
1 public static String leer(BufferedReader sin) {
2 StringBuffer line = new StringBuffer();
3
4 try {
5
6 for (int ch; (ch = sin.read()) != 1; ){
7 line.append(ch);
8 }
9
10 } catch (IOException e) {
11 System.out.println("leer: " + e.toString());
12 }
13 if (linea != null)
14 System.out.println(line.substring(0));
15 return line.substring(0);
16 }
//-----
The problem is, at line 6, "sin.read()" returns a int (which is a unicode code) and I need the equivalent character to build a string. How can I obtain the character that corresponds to this unicode code?
Thanks in advance.

You may cast the type to char. The loop condition does need some int, I guess if you do the casting in the loop condition, there would be some problem....hmmm, but where should you cast it? Maybe try here: line.append((char)ch); But I am not sure of this....
BTW, try to use the UBB tab "CODE", it would make others much easier to read your code
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Unicode characters
 
Similar Threads
Index of the last character of Strings
Filter Non-Standard Characters
Unicode character
Unicode character
who can get the simplest code?