recode() has a problom to convert a string to Unicode

Discussions about product bugs & problems!
Note: This is no replacement for the Official ETM Support!
2 posts • Page 1 of 1
lizhigang2017
Posts:1
Joined: Thu Aug 03, 2017 10:25 am

recode() has a problom to convert a string to Unicode

Post by lizhigang2017 »

Hello, everybody,

I have a problem when I trying to use recode() converting a string to UNICODE encoding string. Unicode encoding will expand a western character with some "\\0" , and for a eastern character will be no problem. The unicode format "\\0" will make WinCC OA string encoding system recgonize as an end of a string.

Problem example:(chinese '??'= hello)

main()
{
string sUTF8 = "??aaa";

string sGB2312= recode(sUTF8,"UTF8","GB2312"); // correct converted.

blob bGB2312;
blobAppendValue(bGB2312, sGB2312,strlen(sGB2312));

blob bUTF8;
blobAppendValue(bUTF8, sUTF8,strlen(sUTF8));


string sUnicode = recode(sUTF8,"UTF8","unicode"); // incorrect converted.

blob bUnicode;

blobAppendValue(bUnicode, sUnicode,strlen(sUnicode));

DebugN(bUTF8,bGB2312,bUnicode);
}

************************
Logviewer :

WCCOAui5:[Blob encountered with 9 items, dump follows
WCCOAui5:e4 bd a0 e5 a5 bd 61 61 61
WCCOAui5:][Blob encountered with 7 items, dump follows
WCCOAui5:c4 e3 ba c3 61 61 61
WCCOAui5:][Blob encountered with 7 items, dump follows
WCCOAui5:ff fe 60 4f 7d 59 61
WCCOAui5:]

WCCOAui5:ff fe 60 4f 7d 59 61 -------> correct target encoding should be WCCOAui5:ff fe 60 4f 7d 59 61 00 61 00 61 00

best regards!

Li Zhigang

mkoller
Posts:741
Joined: Fri Sep 17, 2010 9:03 am

Re: recode() has a problom to convert a string to Unicode

Post by mkoller »

Right, that is not possible, since - as you said - strings in WinCC_OA are 0-terminated, so they can only store multibyte encoded strings without 0-bytes.
That is the reason why UTF8 exists - no 0 bytes but all unicode characters can be encoded.

2 posts • Page 1 of 1