Why PowerBuilder Changed To Unicode in PowerBuilder 10

 

Sybase PowerBuilder 10 supports a comprehensive set of features for working with Unicode and building multi-language, internationalized applications. The multi-language features are implemented at a fundamental level; the PowerBuilder environment itself is now converted to support Unicode.

The Unicode-enabled underlying system drives Unicode-enabled PowerBuilder applications that are capable of reading files and databases containing multi-language content and presenting this content to end users in a culturally appropriate rendering of their language.

Here is the full scoop on PowerBuilder and Unicode from Sybase.com.

Converting from Unicode to ANSII or vice-versa

PowerBuilder 10 uses Unicode (UTF-16 little endian) internally. PowerBuilder is written in C++
and all internal string manipulation is Unicode compliant as of PowerBuilder 10. PowerBuilder
versions 7, 8, and 9 used double-byte character sets (DBCS); and PowerBuilder versions 6 and
earlier used ASCII. This internal upgrade to Unicode means all PowerBuilder 10 applications are
also fully capable of supporting Unicode and therefore multiple languages. PowerBuilder 10 has
added PowerScript functions to process Unicode and ANSI/DBCS characters and the sources for
the characters, such as Unicode and ANSI/DBCS databases and files.

Convert data to ANSI

Blob lbl_data

lbl_data = Blob("PowerBuilder is cool!", EncodingANSI!)
ls_data = String(lbl_data, EncodingANSI!)

Convert data read via file to ANSI

Blob lbl_data

lbl_data = Blob("PowerBuilder is cool!", EncodingANSI!)
ls_data = String(lbl_data, EncodingANSI!)

Blob Type – Blob is a binary data type. A Blob can store binary data, ANSI characters, or Unicode characters. The String() and Blob() functions support the conversions between the types. The functionality contained in the String() and Blob() functions obviate the need for the older functions FromANSI() and ToANSI(), FromUnicode(), and ToUnicode(). These functions are still supported in PowerBuilder 10, but deprecated; users are encouraged to migrate to the String() and Blob() functions.
The String() and Blob() functions require an encoding parameter. The encoding parameter is one of the following:

  • EncodingANSI!
  • Encoding UTF8!
  • EncodingUTF16LE! – UTF-16 Little Endian encoding (PowerBuilder 10 default)
  • EncodingUTF16BE! – UTF-16 Big Endian encoding

To convert a Blob to a String use:

String ( blob, {Encoding} )
For example:

String str
 str = String(Blb) // Absence of encoding defaults to UTF16LE
 str = String(Blb, EncodingUTF8!) // Use UTF8 encoding

To convert a String to a Blob use:
Blob ( string, {Encoding} )

// Example
 Blob Blb
 Blb = Blob("Some Text") // Absence of encoding parameter defaults to UTF16LE

 Blob Blb
 Blb = Blob("Some Text", EncodingUTF8!) // Use UTF8 encoding

File Functions in PowerBuilder supporting the encoding argument

li_FileNum = FileOpen("EmployeeU.txt", TextMode!, Read!, EncodingUTF16LE!)

Tags:

2 Responses

    • Hi Mohamed. Not sure if I replied to you or not. You do not need to convert to UTF-8 using PB 7 because it is used internally. Well if for some reason you DO need to convert to UTF-8 in PB7 then I don’t know what you’d do possibly find a Windows function that can be used to make the conversion? Anyway PB7 is UTF8 by default so you should not need to worry.

Leave a Reply

Your email address will not be published. Required fields are marked *