【发布时间】:2017-11-25 06:50:35
【问题描述】:
orig_string = "\\\\file_foo\\bar\\text-to-be-deleted\\foo-bar.pdf"
需要修改原始字符串(复制到新变量中),使其看起来像下面的 new_string。该文件有数千行格式相同(pdf文件的文件路径)。
new_string = "\\\\file_foo\\bar\\foo-bar.pdf"
如何修改 orig_string 使其看起来像新字符串?
编辑: 对不起,我忘了在我的原始帖子中提及。 '\text-to-be-deleted' 不一样。所有文件路径都有不同的 '\text-to-be-deleted' 字符串。
例如
"\\\\file_foo\\bar\\path100\\foo-bar.pdf"
"\\\\file_foo\\bar\\path-sample\\foo-bar.pdf"
"\\\\file_foo\\bar\\another-text-be-deleted\\foo-bar.pdf"
... 等等。
【问题讨论】:
标签: python string replace filepath