How to replace � in a string

前端 未结 10 467
挽巷
挽巷 2020-11-28 07:50

I have a string that contains a character � I haven\'t been able to replace it correctly.

String.replace(\"�\", \"\");

doesn\'t work, d

相关标签:
10条回答
  • 2020-11-28 08:45

    dissect the URL code and unicode error. this symbol came to me as well on google translate in the armenian text and sometimes the broken burmese.

    0 讨论(0)
  • 2020-11-28 08:51

    That's the Unicode Replacement Character, \uFFFD. (info)

    Something like this should work:

    String strImport = "For some reason my �double quotes� were lost.";
    strImport = strImport.replaceAll("\uFFFD", "\"");
    
    0 讨论(0)
  • 2020-11-28 08:52

    profilage bas� sur l'analyse de l'esprit (french)

    should be translated as:

    profilage basé sur l'analyse de l'esprit

    so, in this case � = é

    0 讨论(0)
  • 2020-11-28 08:53

    You are asking to replace the character "�" but for me that is coming through as three characters 'ï', '¿' and '½'. This might be your problem... If you are using Java prior to Java 1.5 then you only get the UCS-2 characters, that is only the first 65K UTF-8 characters. Based on other comments, it is most likely that the character that you are looking for is '�', that is the Unicode replacement character. This is the character that is "used to replace an incoming character whose value is unknown or unrepresentable in Unicode".

    Actually, looking at the comment from Kathy, the other issue that you might be having is that javac is not interpreting your .java file as UTF-8, assuming that you are writing it in UTF-8. Try using:

    javac -encoding UTF-8 xx.java
    

    Or, modify your source code to do:

    String.replaceAll("\uFFFD", "");
    
    0 讨论(0)
提交回复
热议问题