【问题标题】:How to convert the given string to desired string as shown below in Python如何将给定的字符串转换为所需的字符串,如下所示的 Python
【发布时间】:2019-10-08 16:08:44
【问题描述】:

给定字符串:

p\u00e5 \u00e5rsbasis i marts.<br><br>P\u00e5 \u00e5rsbasis faldt industriproduktionen 0,6 procent (-0,3) mod analytikerkonsensus, der afventede et fald p\u00e5 0,8 procent.<br><br><table><tbody><tr><td>Eurozonen, %<\/td><td>marts, 2019<\/td><td>Konsensus<\/td><td>februar, 2019<\/td><\/tr><tr><td>Industriproduktion, YY<\/td><td>-0,6<\/td><td>-0,8<\/td><td>-0,3<\/td><\/tr><\/tbody><\/table>Konsensusdata

想要的字符串:

på årsbasis i marts.<br><br>På årsbasis faldt industriproduktionen 0,6 procent (-0,3) mod analytikerkonsensus, der afventede et fald på 0,8 procent.<br><br><table><tbody><tr><td>Eurozonen, %</td><td>marts, 2019</td><td>Konsensus</td><td>februar, 2019</td></tr><tr><td>Industriproduktion, YY</td><td>-0,6</td><td>-0,8</td><td>-0,3</td></tr></tbody></table>Konsensusdata

【问题讨论】:

  • 根据您的问题,我们甚至无法猜测第一个字符串是 unicode(普通 Python 3)字符串还是字节(Python 2)字符串。这很重要。这意味着问题不清楚。我真的认为你应该阅读(再次?)How to Ask :-)。

标签: python string


【解决方案1】:

你可以试试:

string = b"p\u00e5 \u00e5rsbasis i marts.<br><br>P\u00e5 \u00e5rsbasis faldt industriproduktionen 0,6 procent (-0,3) mod analytikerkonsensus, der afventede et fald p\u00e5 0,8 procent.<br><br><table><tbody><tr><td>Eurozonen, %<\/td><td>marts, 2019<\/td><td>Konsensus<\/td><td>februar, 2019<\/td><\/tr><tr><td>Industriproduktion, YY<\/td><td>-0,6<\/td><td>-0,8<\/td><td>-0,3<\/td><\/tr><\/tbody><\/table>Konsensusdata"
print(string.decode('unicode_escape'))

输出:

'på årsbasis i marts。

På årsbasis faldt industriproduktionen 0,6 procent (-0,3) mod analytikerkonsensus, der afventede et fald på 0,8 procent。

Eurozonen, %marts, 2019共识2019年2月Industriproduktion, YY-0,6 -0,8-0,3Konsensusdata'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-15
    • 1970-01-01
    • 1970-01-01
    • 2014-04-19
    • 1970-01-01
    • 2013-06-14
    • 1970-01-01
    相关资源
    最近更新 更多