Skip to main content
September 23, 2014
Question

How to convert character into Unicode value?

  • September 23, 2014
  • 2 replies
  • 2095 views

Being new to Indesign SDK development I have problem to convert the const char* into unicode value. And I am tried with the following code,But it gives the actual character..

  UTF16TextChar *toUTFString = new UTF16TextChar[1];

  int32 numWChars = ::CTUnicodeTranslator::Instance()->CharToTextChar(str, 1, toUTFString, 1);

  PMString myString;

  myString.AppendW(toUTFString, numWChars);

  CAlert::InformationAlert(myString);

Please some one help me to that problem..Thanks in advance.

This topic has been closed for replies.

2 replies

Inspiring
September 26, 2014

I suggest using WideString:

WideString uniString;

uniString.SetCString(str);

PMString myString;

myString.AppendW(uniString.begin());

CAlert::InformationAlert(myString);

Dan_Korn
Inspiring
September 24, 2014

Why do you think that the result you're getting is wrong?

You're passing 1 for the "writingscript" parameter, so it's not obvious what the encoding of the 8-bit character you're passing in is supposed to be, but if the 8-bit character you're starting out with is an ASCII character (code point less then 128), or if it's Latin-1, then the equivalent Unicode code point is going to be exactly the same as the 8-bit value, just padded to a 16-bit value.  So I would expect to get the "actual character" back, especially if you're not specifying any particular starting encoding.

In this regard, the "char to text char" function is trivial for converting a single 8-bit character, especially with no encoding specified.  I would think it would be a lot more useful for converting something like UTF-8 to UTF-16, although that's not going to do you much good with a single 8-bit character either, especially if that particular single byte is part of a UTF-8 escape sequence.  Or it could be used to convert some other 8-bit encoding (other than Latin-1), such as Mac Roman, to UTF-16 Unicode.

September 25, 2014

Thanks for your Reply,

      Can u help me to convert the special characters to unicode value.



Dan_Korn
Inspiring
September 25, 2014

Your screenshot shows the Unicode code point for that Copyright Sign character: 0xA9, or 169 decimal.  What is there to convert?