用ASCII字符编码字符串(查找和替换?)

2024-05-29 04:11:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个像下面这样的字符串:

THE SMASH-HIT, CRITICALLY ACCLAIMED SERIES RETURNS! Now that you've read the first two bestselling collections of SAGA , you're all caught up and ready to jump on the ongoing train with Chapter Thirteen, beginning an all-new monthly sci-fi/fantasy adventure, as Hazel and her parents head to the planet Quietus in search of cult romance novelist D. Oswald Heist.

可以看出,撇号(')表示为ASCII码:

^{pr2}$

你建议我如何编码这个字符串?在

其他ascii码也出现了:

"
&

Tags: andoftheto字符串youallnow
1条回答
网友
1楼 · 发布于 2024-05-29 04:11:09

它们被称为HTML entities。最简单的方法是从标准库中使用HtmlParser

>>> s = "THE SMASH-HIT, CRITICALLY ACCLAIMED SERIES RETURNS! Now that you've read the first two bestselling collections of SAGA , you're all caught up and ready to jump on the ongoing train with Chapter Thirteen, beginning an all-new monthly sci-fi/fantasy adventure, as Hazel and her parents head to the planet Quietus in search of cult romance novelist D. Oswald Heist."
>>> import HTMLParser
>>> HTMLParser.HTMLParser().unescape(s)
u"THE SMASH-HIT, CRITICALLY ACCLAIMED SERIES RETURNS! Now that you've read the first two bestselling collections of SAGA , you're all caught up and ready to jump on the ongoing train with Chapter Thirteen, beginning an all-new monthly sci-fi/fantasy adventure, as Hazel and her parents head to the planet Quietus in search of cult romance novelist D. Oswald Heist."

另请参见:

相关问题 更多 >

    热门问题