Here is the file content:
H\u00f6gskolan
Högskolan
(Note: \u00f6 is actually ö)
I want to replace all ö characters with o, and save it to a new file.
The regular string replace doesn't work as expected.
with open("test.txt", encoding="utf-8") as f:
content = f.read()
replacedContent = content.replace("ö", "o")
with open("testOutput.txt", "w", encoding="utf-8") as f:
f.write(replacedContent)
testOutput.txt file content:
H\u00f6gskolan
Hogskolan
I found a similar question but its solution didn't work as well:
import codecs
with open("test.txt", encoding="utf-8") as f:
content = f.read()
content = codecs.decode(content, "unicode_escape")
replacedContent = content.replace("ö", "o")
with open("testOutput.txt", "w", encoding="utf-8") as f:
f.write(replacedContent)
testOutput.txt file content:
Hogskolan
Högskolan
Any idea how to achieve this?