Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing double quotes from a string in Java [closed]

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\"");
like image 359
Kanaga Thara Avatar asked Oct 11 '13 10:10

Kanaga Thara


People also ask

How do you remove double quotes from a string in Java?

To remove double quotes just from the beginning and end of the String, we can use a more specific regular expression: String result = input. replaceAll("^\"|\"$", ""); After executing this example, occurrences of double quotes at the beginning or at end of the String will be replaced by empty strings.

How do you remove double quotes from a string?

Use the String. replaceAll() method to remove all double quotes from a string, e.g. str. replaceAll('"', '') . The replace() method will return a new string with all double quotes removed.

How do you close a double quote?

There are four curly quote characters: the opening single quote ( ' ), the closing single quote ( ' ), the opening double quote ( “ ), and the closing double quote ( ” ).


3 Answers

You can just go for String replace method.-

line1 = line1.replace("\"", "");
like image 98
ssantos Avatar answered Oct 17 '22 16:10

ssantos


Use replace method of string like the following way:

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

Output:

abcd
like image 39
SpringLearner Avatar answered Oct 17 '22 16:10

SpringLearner


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

have a look here

like image 24
Isuru Gunawardana Avatar answered Oct 17 '22 15:10

Isuru Gunawardana