Hello,
We have to convert blob data into string. The blob content could be encoded in UTF8, ANSI or UTF16LE.
How to identify which encoder to use for string conversion?
Thank you,
Yuri
Hello,
We have to convert blob data into string. The blob content could be encoded in UTF8, ANSI or UTF16LE.
How to identify which encoder to use for string conversion?
Thank you,
Yuri
See also this newer thread for some comments and a complex work-around I came up with to handle unknown files that might or might not have the expected Byte Order Marks: https://community.appeon.com/index.php/qna/q-a/opening-unicode-files-without-boms
This might be helpful:
https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-istextunicode
Function boolean IsTextUnicode ( ref blob lpv, long iSize, ref long lpiResult ) Library "advapi32.dll"
You could add another column which contains a code to tell you the format. The process that stores the blob should know what the format is and could update the format column.
blob is from database ...
If the blob's contents are being read from a file, you can use the FileEncoding( filename ) PowerScript function.
I manually wrote the code below. I'd except that PB natively identify the encoder when converting blob to string.
encoding enc
byte b1, b2
enc = EncodingUTF8!
if not isNull(ab_data) then
if len(ab_data) >= 2 then
b1 = byte(blobmid(ab_data,1,1))
b2 = byte(blobmid(ab_data,2,1))
if b1 = 255 and b2 = 254 then
enc = EncodingUTF16LE!
elseif b1 = 254 and b2 = 255 then
enc = EncodingUTF16BE!
end if
end if
end if
return enc