有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!


共 (5) 个答案

  1. # 1 楼答案

    您真的应该在Java代码中使用UNICODE,例如:

        //Use a string literal to assign a value to the String
        String address = "I live at 22b Baker Street!";
    
        //The same string but using Unicode values
        String unicodeAddress = "\u0049\u0020\u006C\u0069\u0076\u0065"
                + "\u0020\u0061\u0074\u0020\u0032\u0032\u0042\u0020"
                + "\u0042\u0061\u006B\u0065\u0072\u0020\u0053\u0074"
                + "\u0072\u0065\u0065\u0074\u0021";
    
        System.out.println("Here is Sherlock's address: " + address); 
        System.out.println("It even works using Unicode characters: " + unicodeAddress); 
    

    示例取自here

    我还发现this resource对查找unicodes很有用

    它避免了与特殊字符编码相关的各种问题

  2. # 2 楼答案

    如果知道该字符的unicode字符代码,可以使用\uxxx方法将字符放入代码中的字符串中

  3. # 4 楼答案

    使用Notepad++(在Windows上)或任何文本编辑器打开显示特殊字符的文件。然后,复制该字符并将其粘贴到该URL(https://unicode-table.com/en/)中。通过这种方式,您可以获得该字符的四位unicode

    例如,在此伪代码中,检查字符串中是否存在特殊字符(右箭头)

    String s = "[O2] = 8.1 ppb→ 0 ppb";
    
    if(s.indexOf("\u2192") != -1)
    {
        System.out.println("Character \u2192 is present in the string");
    }