问题描述
我正在阅读PDF文件,并将每个文件转换为长字符串。字符串中的某些词带有卷曲的语音标记,如下所示:
“florals”
我想将这些卷曲的部分转换为直的语音标记:
"florals"
有什么办法可以做到这一点?
原因是当我将程序转换为可执行文件时给我一个unicode错误-因此想扫描字符串并进行更改。
解决方法
使用.replace()
的语法是string.replace('charcater you want to replace','character your using to replace')
sentence = '“Florals”'
sentence = sentence.replace('“','"').replace('”','"')
print(sentence)
.replace()
被调用了两次,因为您想替换两个字符“
和”
。