Convert Ansi or OEM String to UTF-8

This forum is for eXpress++ general support.
Post Reply
Message
Author
User avatar
PedroAlex
Posts: 229
Joined: Tue Feb 09, 2010 3:06 am

Convert Ansi or OEM String to UTF-8

#1 Post by PedroAlex »

Hi people.

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

User avatar
rdonnay
Site Admin
Posts: 4722
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: Convert Ansi or OEM String to UTF-8

#2 Post 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
The eXpress train is coming - and it has more cars.

User avatar
Tom
Posts: 1165
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

Re: Convert Ansi or OEM String to UTF-8

#3 Post by Tom »

Pablos OT4XB (free) contains several functions to do this.
Best regards,
Tom

"Did I offend you?"
"No."
"Okay, give me a second chance."

Piotr D
Posts: 129
Joined: Mon Jul 28, 2014 1:26 am
Location: Poznań, Poland

Re: Convert Ansi or OEM String to UTF-8

#4 Post 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

User avatar
PedroAlex
Posts: 229
Joined: Tue Feb 09, 2010 3:06 am

Re: Convert Ansi or OEM String to UTF-8

#5 Post 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.
Pedro Alexandre

User avatar
Tom
Posts: 1165
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

Re: Convert Ansi or OEM String to UTF-8

#6 Post 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?
Best regards,
Tom

"Did I offend you?"
"No."
"Okay, give me a second chance."

User avatar
PedroAlex
Posts: 229
Joined: Tue Feb 09, 2010 3:06 am

Re: Convert Ansi or OEM String to UTF-8

#7 Post 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.
Last edited by PedroAlex on Tue Oct 27, 2020 4:16 am, edited 1 time in total.
Pedro Alexandre

User avatar
Tom
Posts: 1165
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

Re: Convert Ansi or OEM String to UTF-8

#8 Post 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/
Best regards,
Tom

"Did I offend you?"
"No."
"Okay, give me a second chance."

User avatar
Auge_Ohr
Posts: 1405
Joined: Wed Feb 24, 2010 3:44 pm

Re: Convert Ansi or OEM String to UTF-8

#9 Post 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
greetings by OHR
Jimmy

User avatar
PedroAlex
Posts: 229
Joined: Tue Feb 09, 2010 3:06 am

Re: Convert Ansi or OEM String to UTF-8

#10 Post 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.
Pedro Alexandre

Post Reply