我有一个类型为 ../sometext/someothertext
的字符串,我正在尝试替换 ..
在带有网站名称的字符串中 http://www.website.com
.
在 Python 中,我所做的是这样的:
strName = "../sometext/someothertext"
strName.replace("..", "http://www.website.com")
print strName
但我得到的唯一输出是
../sometext/someothertext
我也试过逃避句号,比如
strName = ../sometext/someothertext
strName.replace("\.\.", "http://www.website.com")
但输出不会改变。我该怎么做呢?
最佳答案
你没有分配结果......
strName = strName.replace("..", "http://www.website.com")
.replace
不修改原始字符串,而是返回一个带有修改的新字符串。
关于python - 替换字符串中的句点 ("."),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14750942/