Page 1 of 1

Convert Ansi or OEM String to UTF-8

Posted: Fri Oct 23, 2020 9:25 am
by PedroAlex
Hi people.

Do you know if the xBase or eXpress has any function for converting a string to utf-8?

Re: Convert Ansi or OEM String to UTF-8

Posted: Fri Oct 23, 2020 10:21 am
by rdonnay
Str2Unicode()
Converts an OEM/ANSI/ASCII character string to a Unicode string.

Str2Unicode( <cString> ) --> cuString

Parameters
<cString>
<cString> is an ANSI-encoded character string.

Return
The function returns a character string in Unicode format.

Description
Function Str2Unicode() converts an ANSI character string to Unicode format. The primary usage of Str2Unicode() is in conjunction with the native platform API.

Note: Str2Unicode() returns a string in UTF-16 Little Endian encoding, which is the native encoding used for Unicode character strings on the Windows platform.

See also
Unicode2Str()
IsUnicode()

File info
Static library
xppdui.lib
Dynamic library
xppdui.dll

Re: Convert Ansi or OEM String to UTF-8

Posted: Sun Oct 25, 2020 8:29 am
by Tom
Pablos OT4XB (free) contains several functions to do this.

Re: Convert Ansi or OEM String to UTF-8

Posted: Mon Oct 26, 2020 5:33 am
by Piotr D
Yes, Pablos OT4XB conert easy, but use more and more memory after each call. I use instead functions from xb2net (Boris Borzic).

Piotr

Re: Convert Ansi or OEM String to UTF-8

Posted: Mon Oct 26, 2020 10:36 am
by PedroAlex
Hi people.

this function str2unicode() does not work.

It no return any Value.

maybe I´m not understaind the syntax usage or Perhaps I am not understanding how it is used.

If I do :

MyStringUTF := str2unicode('Pedro Alexandre Caliço Bagarrão')

the result returned to MyStringUTF is 'P'

The result does not make sense.

Re: Convert Ansi or OEM String to UTF-8

Posted: Tue Oct 27, 2020 12:50 am
by Tom
Look at the docs, Pedro: "Note: Str2Unicode returns a string in UTF-16 Little Endian encoding, which is the native encoding used for Unicode character strings on the Windows platform." And, above: "The primary use is in conjunction with the native platform API." Str2Unicode is used to send parameters to API calls. You can't display UTF-16 in your app. The return value is not a valid string for Xbase++ functions, since they expect 8-bit-OEM or ANSI.

Try the functions from Pablos OT4XB like "cAnsiToUtf8()" or "cOemToUtf8()" or those from Xb2.Net ("xbCPConvert()" and others).

What are you trying to do?

Re: Convert Ansi or OEM String to UTF-8

Posted: Tue Oct 27, 2020 3:33 am
by PedroAlex
Hi Tom.

I´m workinh on QRCode to print on billing documents.
to create the qrcode according to the specifications required by law it is necessary send the data in UTF-8 format.
The string to be sent can be about 500 characters.

Re: Convert Ansi or OEM String to UTF-8

Posted: Tue Oct 27, 2020 3:53 am
by Tom
Hi, Pedro.

Try Pablos functions, they work well, and I can't confirm they're eating ressources. Just include ot4xb.ch in your source files, link ot4xb.lib to your app and deliver ot4xb.dll with it. https://blog.xbwin.com/

Re: Convert Ansi or OEM String to UTF-8

Posted: Tue Oct 27, 2020 5:52 pm
by Auge_Ohr
hi,
PedroAlex wrote: Tue Oct 27, 2020 3:33 am I´m workinh on QRCode to print on billing documents.
to create the qrcode according to the specifications required by law it is necessary send the data in UTF-8 format.
The string to be sent can be about 500 characters.
Printing can be "external" ...
when have so many characters it is most "store" into JSON Format.

under harbour i use HMG Contribution to Print "any" Barcode / QRcode with HMG_Zebra

but it have a BUG in \Source\h_HMG_Zebra.Prg
https://www.hmgforum.com/viewtopic.php? ... 93&start=9

have a look here https://github.com/HMG-Official/HMG if it was fixed in latest HMG Contribution

Re: Convert Ansi or OEM String to UTF-8

Posted: Wed Oct 28, 2020 4:12 am
by PedroAlex
Tom.
Jimmy.

Thank you for your help.

I think I already found the way.
StrokeScribe Activex Control can do both. Convert the string to utf and create the qrcode.
I'm doing tests and it seems to me that maybe it is the solution.