Convert GBK to utf8 string in python

前端 未结 5 1870
面向向阳花
面向向阳花 2021-01-07 04:16

I have a string.

s = u\"

        
5条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-07 04:41

    If you can keep the alert in a separate string "a":

    a = '\xc7\xeb\xca\xe4\xc8\xeb\xd5\xfd\xc8\xb7\xd1\xe9\xd6\xa4\xc2\xeb,\xd0\xbb\xd0\xbb!'.decode("gbk")
    s = u""
    print s
    

    Then it will print:

    
    

    If you want to automatically extract the substring in one go:

    s = ""
    s = unicode("'".join((s.decode("gbk").split("'",2))))
    print s
    

    will print:

     
    

提交回复
热议问题