Question about TEXT()'s function, TEXT() implementation, and character encoding

Hi all,

I’ve got a number of questions:

  1. Is my understanding of TEXT(), written below, correct?
  2. What are the character encoding methods like ANSI, ASCII, and TCHAR, and how do they differ?
  3. Is there an easier way to implement TEXT() without having to individually implement it across all strings?

I’ll try and explain my understanding of what TEXT() does, and please correct me where I’m wrong: Having tried to read through the linked material, would it be correct to say TEXT() converts the string from ANSI to TCHAR, so as to be readable on other platforms?

If this is correct, what is the default encoding method, and why is it the default (I believe I read somewhere in the linked material that the default encoding method is ANSI but I thought all characters were considered ASCII). Why can this type of character encoding not be read easily by other platforms?

If you need me to separate these into different topics let me know, I’m still new on forum rules.

  1. That is a pretty big and complex topic and I’m honestly not sure it’s worth going into. Though I will say of those listed, only ASCII is a character encoding.
  2. The implementation of TEXT on Microsoft platforms is just
    #define TEXT(x) L##x
    
    Which means to concatenate whatever you give it with an L.
    e.g. TEXT("Hello") will expand to L"Hello"

No, it does 0 conversions.

There is no encoding. char just stores 8 bits (typically), there’s no encoding information in that. If you then use that for something that uses a different character encoding than what you expected it to use (e.g. Greek vs Arabic) then what is displayed may be different to what you were expecting.


Unreal uses Unicode and different platforms use different types to store Unicode code points. On Windows (and I assume Xbox/other Microsoft plaforms) use wchar_t others like Linux use char.

This is all the TEXT macro and TCHAR does, it’s to make it the correct type for the platform being targeted.

"Hello"  // const char[6]
L"Hello" // const wchar_t[6]
u"Hello" // const char16_t[6]

That’s it. It’ll prepend one of those (or do nothing) to make the literal the correct type.

Thanks so much for your answer! I will go look up the definition of concatenate in a bit, and thank you for clarifying really appreciate it :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms