如何删除第一个和最后一个双引号
16lz
2021-01-22
I want to strip double quotes from
我想从中删除双引号
string = '"" " " ""\\1" " "" ""'
to become
成为
string = '" " " ""\\1" " "" "'
I tried to use rstrip
, lstrip
and strip('[^\"]|[\"$]')
but it did not work.
我尝试使用rstrip,lstrip和strip('[^ \“] | [\”$]')但它没有用。
How can I do this? Thank you for helping me.
我怎样才能做到这一点?感谢你们对我的帮助。
12 个解决方案
#1
140
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]
string = string [1:-1]