Remove Double Quotes from String

How can I trim beginning and ending double quotes from a string?

You can use String#replaceAll() with a pattern of ^\"|\"$ for this.

E.g.

string = string.replaceAll("^\"|\"$", "");

To learn more about regular expressions, have al ook at http://regular-expression.info.

That said, this smells a bit like that you're trying to invent a CSV parser. If so, I'd suggest to look around for existing libraries, such as OpenCSV.

Remove quotes from String in Python

Just use string methods .replace() if they occur throughout, or .strip() if they only occur at the start and/or finish:

a = '"sajdkasjdsak" "asdasdasds"' 

a = a.replace('"', '')
'sajdkasjdsak asdasdasds'

# or, if they only occur at start and end...
a = a.strip('\"')
'sajdkasjdsak" "asdasdasds'

# or, if they only occur at start...
a = a.lstrip('\"')

# or, if they only occur at end...
a = a.rstrip('\"')

Removing the double quotes from a string

Try this...

Dim s as String = "['C:\Users\Elvin Gentiles\Desktop\RiceLAB\BLB01.JPG';'C:\Users\Elvin Gentiles\Desktop\RiceLAB\BLB02.JPG']"
s = s.Replace("'", "").Trim()

Any character or word or phrase or even a sentence is considered a string when it's enclosed in double quotes, but if the value of your string literally has double quotes, like this "SAMPLE", and you want to remove the double quotes, then do something...

Dim s as String = ""['C:\Users\Elvin Gentiles\Desktop\RiceLAB\BLB01.JPG';'C:\Users\Elvin Gentiles\Desktop\RiceLAB\BLB02.JPG']""
s = s.Replace("""", "").Trim()

Yes I noticed...double double quotes...I equated s to something that you say is passed from MATLAB, the string literally has double quotes, so to remove this, you replace double double quotes with nothing. That's how you do it in .NET. Your compiler interprets double double quotes as just a single quote :)

How can I remove double quotes from a string

Supposed you have

var currntDate =  @"""'2017-08-03'""";

Just use

currntDate = currntDate.Replace("\"","");

How to remove double quotes from list of strings?

Try this:

VERSION = ["'pilot-2'", "'pilot-1'"]
VERSIONS_F = []
for item in VERSION:
temp = item.replace("'",'')
VERSIONS_F.append(temp)
print (VERSIONS_F)

it will print ['pilot-2','pilot-1']



Related Topics



Leave a reply



Submit