Home > other >  Replace apostrophe with whitespace in java
Replace apostrophe with whitespace in java

Time:10-31

I want to replace all the apostrophes inside a string with a whitespace. But i tried this and it doesn't work. How can i solve this?

inputString = inputString.replaceAll("'", " ");

CodePudding user response:

Looking at the input string you shared in the comments ("Così tra questa Immensità s’annega il pensier mio"), the character there isn't a regular single quote ('), but an apostrophe (’), so you should use that in your replaceAll call:

inputString = inputString.replaceAll("’", " ");

You could also use a regex to replace both quotes and apostrophes, of course:

inputString = inputString.replaceAll("[’']", " ");

CodePudding user response:

This might be due to escape character

use this insted

inputString = inputString..replaceAll("\'","")

for all list you can visit this

  • Related