Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to remove special characters from string in a file using java

I have text file it contains following information.My task is to remove special symbols from that text file.My input file conatins

This is sample CCNA program. it contains CCNP™.

My required output string:

This is sample CCNA program. it contains CCNP.

how to do this please suggest me.

thanks

like image 203
user2609542 Avatar asked Nov 24 '25 08:11

user2609542


1 Answers

This should work, "if you're looking to retain only ASCII (0-127) characters in your string":

String str = "This is sample CCNA program. it contains CCNP™";
str = str.replaceAll("[^\\x00-\\x7f]+", "");
like image 101
anubhava Avatar answered Nov 25 '25 20:11

anubhava



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!