Lars Werkman
Lars Werkman

Reputation: 2528

Replace all special characters

I have a string that looks like this:

<a href=\"test\" />

I want to to replace the /" to ", so that it looks like this <a href="test" />.

Therefore I am using this piece of code:

content = content.replaceAll("\\\"", "\"");

For some reason it doesn't find \". So it isn't being replaced.

Upvotes: 1

Views: 1088

Answers (2)

tckmn
tckmn

Reputation: 59363

replaceAll takes a regex. Therefore, you must escape the escape like this:

s = s.replaceAll("\\\\\"", "\"");

Upvotes: 2

Hossein Mobasher
Hossein Mobasher

Reputation: 4472

Try this code: string.replaceAll(Pattern.quote("\\\""), "\"");

Upvotes: 3

Related Questions