Q:

How to remove the Â character from a string in java?

I have the following string in which the Â  special character is coming in hidden. I want to remove only the Â from this string ~IQBAL~KARACHIÂ¦~~~~~~~~~~~.
Here is a before and after image to show what I mean:

I've tried this code:
responseMessageUTF.replaceAll("\\P{InBasic_Latin}", "");

but this is also replacing the ¦ character. Is there any way to remove only the Â character and not the ¦ character?

A:

I have a simple one liner code, it removes for most of the non-UTF-8 characters. I tested for your character as well i.e. Â.
        String myString = "~KARACHIÂ¦~~~~~~";
        String result = myString.replaceAll("[^\\x00-\\x7F]","");
        System.out.println(result);

You can find complete code here.
You may test that as well here.

A:

You have to use the right UTF:
Code example:
String blub = " ~KARACHIÂ¦~~~~~~";
System.out.println(blub);
System.out.println(blub.replaceAll(new String("Â".getBytes("UTF-8"), "UTF-8"), ""));

Output:
 ~KARACHIÂ¦~~~~~~
 ~KARACHI¦~~~~~~

See a description similiar to this problem here: Link

