0
mystr="MYCOMPANY® PREMIER VISA SIGNATURE® CARD"

I tried below ways, but it is not removing the Â.

mystr= Normalizer.normalize(mystr, Normalizer.Form.NFD)
mystr= Pattern.compile("\\p{InCOMBINING_DIACRITICAL_MARKS}+").matcher(mystr).replaceAll("");

Is there any way to remove the accent characters from above string except the characters like Copyright, Trademark and Registered.

expectedString = "MYCOMPANY® PREMIER VISA SIGNATURE® CARD"
  • Does this answer your question? [Is there a way to get rid of accents and convert a whole string to regular letters?](https://stackoverflow.com/questions/3322152/is-there-a-way-to-get-rid-of-accents-and-convert-a-whole-string-to-regular-lette) – Abra Nov 01 '20 at 07:47
  • @Abra, above solution is replacing the accent char with a valid letter "A". But I want to remove it completely. – Lokesh Reddy Nov 01 '20 at 08:12
  • The trick then would be to replace it with an empty string (`""`) – Curiosa Globunznik Nov 01 '20 at 08:56
  • 1
    I am going to stick my neck out here and say that what you're asking for isn't what you need. The real problem here looks to a character-set encoding problem. Almost certainly you have received the string `MYCOMPANY® PREMIER VISA SIGNATURE® CARD` in UTF-8 but have incorrectly decoded it using ISO-8859-1 or Windows-1252. In UTF-8, the character `®` is represented by two bytes, but in ISO-8859-1 and Windows-1252, the same two bytes represent the characters `®`. Use the correct encoding Instead of fixing up the results of using the wrong encoding. – Luke Woodward Nov 01 '20 at 10:01

1 Answers1

0

You can achieve this using StringUtils.stripAccents(string); from Apache Commons Lang.
It removes accents from character but won't delete it, so to get your desired result I've compared the two strings and appended the common characters to a new string.
Download the latest version of binaries from their website or you can directly download the JAR from this link.
Add the JAR libraries through your IDE and import it in code as shown:

import org.apache.commons.lang3.StringUtils;

public class Solution
{
    public static void main(String args[])
    {
        String string1 = "MYCOMPANY® PREMIER VISA SIGNATURE® CARD";
        String string2 = StringUtils.stripAccents(string1);
        int n = string1.length();
        char[] arr1 = string1.toCharArray();
        char[] arr2 = string2.toCharArray();
        StringBuilder sb = new StringBuilder();
        for(int t = 0; t < n; t++)
            if(arr1[t] == arr2[t]) sb.append(arr2[t]);         
        System.out.println(sb);
    }
}

It gives the output:

MYCOMPANY® PREMIER VISA SIGNATURE® CARD
Ankit
  • 682
  • 1
  • 6
  • 14