我正在尝试编写一个Java代码,其中包含包含表情符号的utf8字符串,我想用文本替换该表情符号。例如:
我有这段文字:???? ?????? ?????? ?????? ???????
我希望它像这样:grinningFace ???? ???? ?????? ?????? ?????? ???????
我尝试了这个:
String string = "";
try {
byte[] utf8Bytes = string.getBytes("UTF-8");
string = new String(utf8Bytes, "UTF-8");
} catch (
UnsupportedEncodingException e
) {
e.printStackTrace();
}
string=string.replaceAll("[\u1F600]", "grinningF");
//also tried "\u1F600" and "u1F600"
System.out.println(string);
Run Code Online (Sandbox Code Playgroud)
但这没用,怎么办?