regex - How to transfer unicode string to another format in Java? -
i want query data "morristown\\u002c_new_jersey"
. because in database, "morristown\\u002c_new_jersey"
"morristown\$002c_new_jersey"
. "\\u"
become "\$"
, lowercase in unicode become uppercase. there neat way process kinds of data?
here java code regex \\\\u([^_]+)
replace unicode character code db equivalence:
string str = "jos\\u00e9_a\\u002e_santos"; matcher matcher = pattern.compile("\\\\u([^_]+)").matcher(str); stringbuffer sb = new stringbuffer(); while (matcher.find()) { matcher.appendreplacement(sb, "\\\\\\$" + matcher.group(1).touppercase()); } matcher.appendtail(sb); system.out.println("the original string "+ str+ "\n has been converted "+ sb.tostring());
prints:
the original string jos\u00e9_a\u002e_santos has been converted jos\$00e9_a\$002e_santos
the code along matcher class documentation.
Comments
Post a Comment