How to replace � in a string

前端 未结 10 577
挽巷
挽巷 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:32

    As others have said, you posted 3 characters instead of one. I suggest you run this little snippet of code to see what's actually in your string:

    public static void dumpString(String text)
    {
        for (int i=0; i < text.length(); i++)
        {
            System.out.println("U+" + Integer.toString(text.charAt(i), 16) 
                               + " " + text.charAt(i));
        }
    }
    

    If you post the results of that, it'll be easier to work out what's going on. (I haven't bothered padding the string - we can do that by inspection...)

提交回复
热议问题