【发布时间】:2012-03-06 12:11:26
【问题描述】:
假设我想删除字符串周围的所有"。在 Python 中,我会:
>>> s='"Don\'t need the quotes"'
>>> print s
"Don't need the quotes"
>>> print s.strip('"')
Don't need the quotes
如果我想删除多个字符,例如" 和括号:
>> s='"(Don\'t need quotes and parens)"'
>>> print s
"(Don't need quotes and parens)"
>>> print s.strip('"()')
Don't need quotes and parens
在 Java 中剥离字符串的优雅方法是什么?
【问题讨论】:
-
String 类有一个 replace() 方法。它应该满足您的需求。
-
See here 是详细讨论。