将Unicode符号转换为HTML使用Qt。

huangapple go评论96阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年8月5日 12:44:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/76840161.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定