Can I convert a Unicode string to a regular string (including $$)?

Asked 2 years ago, Updated 2 years ago, 96 views

Is it possible to convert a Unicode string to a regular string? If it's just an alphabet, I'll do something about it, but in addition to the alphabet, it also contains special characters such as , and $

type-conversion string python unicode

2022-09-21 21:45

1 Answers

Must be applied in order

import unicodedata

title = u"hello $#@ i'm Demi"
print(unicodedata.normalize('NFKD', title))
print(unicodedata.normalize('NFKD', title).encode('ascii','ignore'))


title = u"Klüft skräms inför på fédéral électoral große"
print(unicodedata.normalize('NFKD', title))
print(unicodedata.normalize('NFKD', title).encode('ascii','ignore'))

Output:

hello $#@ i'm Demi
b"hello $#@ i'm Demi"
Klüft skräms inför på fédéral électoral große
b'Kluft skrams infor pa federal electoral groe'


2022-09-21 21:45

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.