0

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.

Dmitrii
  • 618
  • 2
  • 7
  • 19
  • 1
    Start by writing code which _finds_ and prints all "U-xxxx" substrings. If you can't, ask about that code. Next step, replace these with `.`. next step, replace these with correct unicode character. Next step, handle `\\` escape codes. You now have a correct unicode string. Next step, convert it to HTML text (there should be a function for that, don't need to implement it yourself). – hyde Aug 05 '23 at 06:40
  • That's a good point, but here you are talking about manually replacing all these characters. I thought, that maybe there are some special functions exist – Dmitrii Aug 05 '23 at 08:37
  • No, I'm talking about writing the special function. But, for HTML, you can actually directly replace the markup around the code, without never interpreting it, as shown by the (currently only) answer. – hyde Aug 05 '23 at 21:56

1 Answers1

2

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.

JosefZ
  • 28,460
  • 5
  • 44
  • 83