Convert from encoded unicode String into Java String -
i have string in json data looks this:
#0023sat apr 30 10:46:11 utc 2016#000a[interoperability]interoperability#005c index=unknown (r03)#000a[exif]shutter#005c speed#005c value=1/1999 sec#000a[exif]bits#005c per#005c sample=8 8 8 bits/component/pixel#000a[exif]exposure#005c bias#005c value=0 ev#000a[exif]sub-sec#005c time#005c original=00#000a
all #xxxx words unicode.
how convert java string?
pattern p = pattern.compile("#([0-9a-fa-f]{4})"); matcher m = p.matcher(s); stringbuffer sb = new stringbuffer(); while (m.find()) { int c = integer.parseint(m.group(1), 16); m.appendreplacement(sb, string.valueof((char) c)); } m.appendtail(sb); return sb.tostring();
this assumes #xxxx encodes utf-16 unicode code point. unicode code points supercede 16 bit range of #xxxx.
Comments
Post a Comment