Ritesh
Ritesh

Reputation: 533

remove only double quotes from string before and after square bracket

I am trying to remove double quotes before square bracket like "[ and I am using following code to do it but it says illegal escape charecter.

  str = str.replace("\[","[");

I want to remove only double quotes ie " which is only before square bracket ie [. Please guide me.

Upvotes: 1

Views: 3209

Answers (2)

Frank Neblung
Frank Neblung

Reputation: 3175

Both replace() and replaceAll() do the job. Using replace, you don't have to cope with regular expressions. Don't get confused by the name. In fact replace replaces all occurrences, not just the first.

str = str.replace("\"[", "[");

Upvotes: 1

anubhava
anubhava

Reputation: 785571

You can use:

str = str.replaceAll("\"\\[", "[");

Upvotes: 2

Related Questions