?Java?,???????????????Unicode?????
- ???????Unicode??:
public class UnicodeConverter { public static void main(String[] args) { String input = "Hello, ??!"; String unicode = toUnicode(input); System.out.println("Unicode: " + unicode); } public static String toUnicode(String input) { StringBuilder builder = new StringBuilder(); for (char ch : input.toCharArray()) { builder.append(String.format("\\ux", (int) ch)); } return builder.toString(); } }
- ?Unicode????????:
import java.util.regex.Matcher; import java.util.regex.Pattern; public class UnicodeConverter { public static void main(String[] args) { String unicode = "Hello, \?\?!"; String output = fromUnicode(unicode); System.out.println("Output: " + output); } public static String fromUnicode(String unicode) { Pattern pattern = Pattern.compile("(\\\\u(\\p{XDigit}{4}))"); Matcher matcher = pattern.matcher(unicode); char ch; while (matcher.find()) { ch = (char) Integer.parseInt(matcher.group(2), 16); unicode = unicode.replace(matcher.group(1), ch + ""); } return unicode; } }
???????????????????Unicode???????Unicode??????????????????????????????