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
  • 27,410
  • 9
  • 53
  • 103
user9130953
  • 449
  • 2
  • 13

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
  • 27,410
  • 9
  • 53
  • 103
  • 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