![](/img/trans.png)
[英]How to remove Unicode decimal values of Unicode miscellaneous Symbols in String in Java
[英]How to remove Miscellaneous Symbols Block from the Unicode String
我想使用正則表達式remove miscellaneous symbols block from Unicode string
也可以嘗試,但是它們中的任何一個都不可以使用正則表達式。我認為當前有人可以解決此問題,我如何從字符串中刪除其他符號塊。
Unicode字串
\u263A\uD83D\uDE0A\uD83D\uDE22)\uD83C\uDF82
碼:
String input = "\u263A\uD83D\uDE0A\uD83D\uDE22)\uD83C\uDF82";
input.replaceAll("[\u2600-\u26FF]|[\u2700-\u27BF]", "");
預期:
\uD83D\uDE0A\uD83D\uDE22)\uD83C\uDF82
但我無法解決此問題。
它不起作用,因為String在Java中是不可變的 ,您必須使用將結果分配給輸入的方式如下:
String result = input.replaceAll("[\u2600-\u26FF]|[\u2700-\u27BF]", "");
或者簡單地:
input = input.replaceAll("[\u2600-\u26FF]|[\u2700-\u27BF]", "");
因此,如果您進行這樣的打印:
System.out.println(input);
System.out.println("\uD83D\uDE0A\uD83D\uDE22)\uD83C\uDF82");
兩者都給出:
😊😢)🎂
😊😢)🎂
如果輸入文本包含轉義的u字符(由反斜杠,“ u”和4個十六進制數字組成的文本),請先將其轉換為實char
。
input = StringEscapeUtils.unescapeJava(Input); // From Apache commons
input = input.replaceAll("[\u2600-\u26FF]|[\u2700-\u27BF]", "");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.