Search code examples
htmlqtunicode

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. 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.


Solution

  • 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\\1;", symbols)
    

    returns ┌SYMBOLS┐\n which renders as

    ┌SYMBOLS┐\n

    in a browser.