Removing double quotes from a string in Java

JavaStringReplace

Java Problem Overview


How would I remove double quotes from a String?

For example: I would expect "abd to produce abd, without the double quote.

Here's the code I've tried:

line1 = line1.replaceAll("\"(\\b[^\"]+|\\s+)?\"(\\b[^\"]+\\b)?\"([^\"]+\\b|\\s+)?\"","\"$1$2$3\"");

Java Solutions


Solution 1 - Java

You can just go for String replace method.-

line1 = line1.replace("\"", "");

Solution 2 - Java

Use replace method of string like the following way:

String x="\"abcd";
String z=x.replace("\"", "");
System.out.println(z);

Output:

abcd

Solution 3 - Java

String withoutQuotes_line1 = line1.replace("\"", "");

have a look here

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKanaga TharaView Question on Stackoverflow
Solution 1 - JavassantosView Answer on Stackoverflow
Solution 2 - JavaSpringLearnerView Answer on Stackoverflow
Solution 3 - JavaIsuru GunawardanaView Answer on Stackoverflow