Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I strip first and last double quotes?

I want to strip double quotes from:

string = '"" " " ""\\1" " "" ""' 

to obtain:

string = '" " " ""\\1" " "" "' 

I tried to use rstrip, lstrip and strip('[^\"]|[\"$]') but it did not work.

How can I do this?

like image 544
Walapa Avatar asked Jun 21 '10 14:06

Walapa


People also ask

How do you open and close double quotation marks?

Press-and-hold down the Option key and then press the curly parentheses { key found near the return key for the opening double quotation mark. Press-and-hold the Option and Shift key and then press the curly parentheses { key found near the return key for the closing double quotation mark.

How do you get rid of double quotes in text?

Option 1: Remove any double quotes in a text string with replace('my string','"',''). This will substitute any instance of a double quote anywhere in the string with an empty string.

What do you do when you have two quotation marks?

Quotation marks, double (“”) or single (''), are generally used for direct quotes, certain titles, and words used in a special manner. Quotation marks are ALWAYS used in pairs, one at the beginning of the quoted text and one at the end. The same rule applies to titles and words used in a special sense or for emphasis.

How do you remove double quotes from the beginning and end of a string in Python?

Using the strip() Function to Remove Double Quotes from String in Python. We use the strip() function in Python to delete characters from the start or end of the string. We can use this method to remove the quotes if they exist at the start or end of the string.


1 Answers

If the quotes you want to strip are always going to be "first and last" as you said, then you could simply use:

string = string[1:-1]

like image 166
houbysoft Avatar answered Oct 03 '22 06:10

houbysoft