英文:
Convert Unicode symbols to HTML with Qt
问题
I have a string, which looks, for example, like this:
SYMBOLSU+2510\n
This string has Unicode character U+2510
and new line symbol \n
. I have a log window, which draws HTML. Does it possible to convert in some way this string to HTML, because when I just text this string to the log window it's written as it is SYMBOLSU+2510\n
, but I need to convert U+2510
to its HTML representation and to draw HTML symbol.
Thanks for the help!
PS. Sorry if I messed some definitions, this encoding thing is not something I'm good at.
PPS I use Qt5.
英文:
I have a string, which looks, for example, like this:
SYMBOLSU+2510\n
This string has Unicode character U+2510
and new line symbol \n
. I have a log window, which draws HTML. Dows it possible to convert in some way this string to HLMT, because when I just text this string to the log window it's written as it is SYMBOLSU+2510\n
, but I need convert U+2510
to its HTML representation and to draw HTML symbol.
Thanks for the help!
PS. Sorry if I messed some definitions, this encoding thing is not something I good at.
PPS I use Qt5.
答案1
得分: 2
只返回翻译好的部分:
你没有指定任何特定的语言;例如,在Python中(替换仅捕获的组):
import re
symbols = 'U+250cSYMBOLSU+2510\n'
re.sub("U\+([0-9A-Fa-f]{4})", "&#x\\1;", symbols)
返回 ┌SYMBOLS┐\n
,在浏览器中呈现为
┌SYMBOLS┐\n
英文:
You don't specify any particular language; for instance, in Python (replace merely captured group):
import re
symbols = 'U+250cSYMBOLSU+2510\n'
re.sub("U\+([0-9A-Fa-f]{4})", "&#x\;", symbols)
returns ┌SYMBOLS┐\n
which renders as
┌SYMBOLS┐\n
in a browser.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论