简体   繁体   English

从字符串中取消转义unicode字符

[英]Unescape unicode characters from a string

I have a string which contains unicode characters which looks like this, 我有一个包含Unicode字符的字符串,看起来像这样,

 "u'type'` does not belong to `[u'item1', u'item2']" 

How would I unescape the unicode parts? 我将如何对unicode部分进行转义?

So that it prints out, 以便打印出来

 "'type' does not belong to ['item1', 'item2']" 

You could use the replace method for the string 您可以对字符串使用replace方法

stringToModify = "u'type' does not belong to [u'item1', u'item2']"

stringToModify.replace("u'","'")

What you show here is actually a byte string displaying the representation of three Unicode strings (all of them containing only ASCII characters FWIW). 您在此处显示的实际上是一个字节字符串,显示了三个Unicode字符串的表示形式(它们全部仅包含ASCII字符FWIW)。

If you cannot change the code producing this string your only solution is re.sub() . 如果您无法更改产生此字符串的代码,则唯一的解决方法是re.sub()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM