0
String s = "VIRÚ";

In my string s I have a special charecter, this is a spanish charecter and I want to remove this and all spanish special charecter from my string. How can I remove.

Expected output

VIRU
xingbin
  • 25,716
  • 8
  • 51
  • 94
user9130953
  • 437
  • 2
  • 12

1 Answers1

2

Use StringUtils.stripAccents of Apache Commons:

String output = StringUtils.stripAccents("VIRÚ"); 
System.out.println(output); // VIRU

Maven dependency:

<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-lang3</artifactId>
    <version>3.6</version>
</dependency>
xingbin
  • 25,716
  • 8
  • 51
  • 94
  • It seems good but that method is not found here `The method stripAccents(String) is undefined for the type StringUtils` import org.apache.commons.codec.binary.StringUtils; – user9130953 Jun 25 '18 at 10:31
  • @user9130953 I'm not sure which `StringUtils` you are working with. If you are using Maven, you can add this. – xingbin Jun 25 '18 at 10:35
  • @user9130953 This method is only available in commons lang3 - you're probably using an old (2.x) version where the method isn't available. – Michael Berry Jun 25 '18 at 10:55