-3

Any way to use u8 literal with a varible?

const char* name[32];
(u8)name//something like this

I need to convert name to utf-8 and i just don't know how.

SLI
  • 713
  • 11
  • 29
  • What are you converting it from? – Galik Oct 28 '17 at 00:10
  • thats the problem that i just don't know, working with other people's sources. Software read memory of other program and i just receive this name variable. All fine for english characters, but if there any russian it is with wrong encoded symbols – SLI Oct 28 '17 at 00:22
  • `name` is an array of pointers, this question makes no sense. Please post the real code you are having trouble with – M.M Oct 28 '17 at 00:51

1 Answers1

2

No, you can't use u8 with a variable. It only applies to string literals at compile-time, not to data at runtime.

You say in comments that you are reading data from other processes. You have to know the exact encoding of that data before you can convert it to anything meaningful. Is it already in UTF-8? Or is it in KOI8-R? ISO-8859-5? Don't guess!

You could try performing known hueristics on the data to try to detect the encoding dynamically (and there are 3rd party libraries available for that purpose), but that is still a form of guessing (albeit somewhat educated guessing) and thus subject to potentially misleading results.

If you can't find out the encoding, then you can't safely convert it to UTF-8 (or anything else, for that matter).

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770