Wiki Home

Uni Code

Namespace: VFP
What is Unicode?

When Microsoft refers to Unicode, they usually mean UTC-16. UTC-16 is a two byte character mapping in which each character always consist of two bytes. UTC-16 Unicode characters are one form of Double Byte characters. Multi-byte characters, what Visual FoxPro uses for languages with more than 256 characters, may be either one or two bytes.

There are many different Unicode encodings. Unicode on the Web is usually encoded as UTF-8. Here is information on the various UTF encodings:

In VFP7+ you can convert directly to and from Unicode(UTC-16) to most other encodings using Str Conv.

In VFP6, you need to go a little roundabout:
PROCEDURE UnicodeToString( pcStr )
  LOCAL lcSkel
  lcSkel = StrConv( pcStr,  6 ) && Double Byte <- Unicode
  lcSkel = StrConv( lcSkel, 2 ) && Single byte <- Double Byte
  RETURN LEFT(lcSkel, MAX(AT(chr(0),lcSkel)-1,0) )
PROCEDURE StringToUnicode( pcStr )
  LOCAL lcSkel
  lcSkel = StrConv( pcStr,  1 ) && Single byte -> Double Byte
  lcSkel = StrConv( lcSkel, 5 ) && Double Byte -> Unicode
  RETURN lcSkel+chr(0)

In NT/2K/XP you can print unicode from VFP using API like:
c = ''
FOR i=1 TO 0x5f
  c = c + CHR(i)+CHR(4)
c = c + CHR(0)+CHR(0)
declare integer MessageBoxW in user32 integer, ;
       string lcMessageText , string Titlebartext, integer Dialogtype
MessageBoxW( 0, c,c,0 )

Andrus Moor
Contributors: wgcs, Albert Ballinger

Category Multi Lingual
( Topic last updated: 2003.12.20 04:38:21 PM )