Unicode
The unicode value of "Latin small letter e with acute accent" () is 00E9. Why then does the following code print a question mark?
System.out.println("\u00e9");
Thanks,
Josh
[189 byte] By [
jab630] at [2007-11-11 7:00:05]

# 4 Re: Unicode
Here's a cute program that will shows ASCII to Unicode conversions.
Its from "The Java Class Libraries" by Chan and Lee
import java.awt.*;
import java.awt.event.*;
import java.awt.datatransfer.*;
public class ASCII2Unicode extends Frame implements ActionListener {
public ASCII2Unicode() {
super("Copy Unicode to clipboard");
setFont(new Font("Monospaced", Font.PLAIN, 14));
// Create the 256 buttons.
Panel p = new Panel(new GridLayout(16, 0));
for (int i=0; i<256; i++) {
Button b = new Button("" + (char)i);
// If control character, display hex value.
if (Character.isISOControl((char)i)) {
String s = "0" + Integer.toHexString(i).toUpperCase();
b.setLabel(s.substring(s.length()-2));
}
b.setName(""+(char)i);
// Listen for events.
b.addActionListener(this);
// Add to panel.
p.add(b);
} // end for(i)
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
dispose();
System.exit(0);
}
});
// Layout and show components.
add(p, BorderLayout.CENTER);
pack();
// Center the frame
Dimension ss = Toolkit.getDefaultToolkit().getScreenSize();
setLocation((ss.width-getBounds().width)/2,
(ss.height-getBounds().height)/2);
show();
} // end
public void actionPerformed(ActionEvent evt) {
// Fetch the character.
char c = ((Component)evt.getSource()).getName().charAt(0);
// Format the unicode string for 'c'.
String result = "\\u00" + Integer.toHexString(c&0xff);
// Place result in system clipboard.
StringSelection contents = new StringSelection(result);
getToolkit().getSystemClipboard().setContents(contents, null);
}
// Start the app
public static void main(String args[]) {
new ASCII2Unicode();
}
}
Norm at 2007-11-11 22:42:49 >
