Meryem
Meryem

Reputation: 23

Remove a character from java string using hex code

i would like to remove a character from java string using hex code:

i am trying following code but seems to not be correct as the character isn't replaced: ÿ

String str ="test  ÿ";
str.replaceAll("\\x{9F}","")

is there any thing wrong with the syntax of the hex code? Thanks.

Upvotes: 1

Views: 9042

Answers (2)

István Rábel
István Rábel

Reputation: 492

To mach ÿ you need \u00ff instead, as Jon mentioned.

String replaced = str.replace("\u00ff", "");

in your case.

Upvotes: 1

Hasanuzzaman Rana
Hasanuzzaman Rana

Reputation: 123

Could you please try this:

    public class AsciiHexCode {
    public static void main(String[] args) {
        String  str = "test  ÿ";
        String result = str.replaceAll("[^\\x00-\\x7F]", "");
        System.out.println("result : "+ result);
    }
}

Upvotes: 1

Related Questions