Helloheyyyy
Helloheyyyy

Reputation: 63

How to filter out double quote symbol with replaceAll function

i am trying to filter a string which containing " symbol. I use the function replaceAll to eliminate unwanted " but errors appear.

Here is my expression:

str[i] = str[i].replaceAll("["]", null);

The error message is as follows:

Multiple markers at this line - Syntax error, insert ")" to complete MethodInvocation - Syntax error, insert ";" to complete BlockStatements - The method replaceAll(String, String) in the type String is not applicable for the arguments (String)

I know that eclipse consider the " quote in [ ] as the boundary of the string I wanted to replace. Can anyone give me the correct expression?

Upvotes: 1

Views: 773

Answers (2)

Rod_Algonquin
Rod_Algonquin

Reputation: 26198

problem:

"["]"

the second quotation will consider the opening bracket as a string, and the other 2 characters(]") will be a syntax error.

solution: you need to escape the quotation mark so you can use the quotation character in the string/regex

 "[\"]"

adding null to the replacement parameter will generate an error, so don't put null put an empty string instead.

Upvotes: 1

Gabe Sechan
Gabe Sechan

Reputation: 93668

Try replaceAll("\"","");

You don't want to use null, you want to use empty string.

Upvotes: 2

Related Questions