java - Failing to produce unicode strings dynamically -


in ui of application using unicode strings ranging "\u0900" "\u0959" unicode equivalent of devanagari characters. trying generate these unicode strings dynamically set on buttons of ui. code:

   for(int i=900;  i<=959 ; i++){         string buttontext = "\\"+"u"+integer.tostring(i);         this.add(new createbutton(buttontext)); //createbutton extends jbutton.     } 

it fails horribly, strings displayed , \u900 \u959 instead of devanagari characters themsleves. how solve issue?

you can't create unicode escape sequence ("\u...." recognized compiler). instead, loop through character values , create string string#valueof:

for (char = 0x900; <= 0x959; i++) {     string buttontext = string.valueof(i);     // ... } 

note i'm prefixing numbers 0x, means numbers hexadecimal. because unicode escape sequences composed of 4 hexadecimal digits:

unicodeescape:     \ unicodemarker hexdigit hexdigit hexdigit hexdigit 

Comments

Popular posts from this blog

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -