RAD Studio
ContentsIndex
PreviousUpNext
Wide Character Routines

Wide strings contain two bytes per element and are used in a variety of situations. You may also choose to use wide strings because they simplify some of the string-handling issues in applications that have multiple target locales. Using a wide character encoding scheme has the advantage that you can make many of the usual assumptions about strings that do not work for MBCS systems, which are single byte strings. For wide strings, there is a direct relationship between the number of bytes in the string and the number of elements in the string. In a MBCS string, you have to be concerned about cutting characters in half or mistaking the second part of a character for the start of a different character. There is a similar issue for a wide string. Although elements are all two bytes, characters not in the Basic Multilingual Plane (BMP) require two elements. 

Two types represent wide strings: UnicodeString and WideString. The WideString format is essentially the same as a Windows BSTR. WideString is appropriate for use in COM applications. WideString is not reference counted, so UnicodeString is more flexible and efficient in other types of applications. In addition, more utility functions are available for UnicodeString than WideString, so UnicodeString is generally preferred. This topic deals with WideString, not UnicodeString

VCL now uses the UnicodeString type; it no longer represents string values as single byte or MBCS strings. 

The following functions convert between standard single-byte character strings (or MBCS strings) and Unicode strings:

  • StringToWideChar
  • WideCharLenToString
  • WideCharLenToStrVar
  • WideCharToString
  • WideCharToStrVar
In addition, the following functions translate between WideStrings and other representations:
  • UCS4StringToWideString
  • WideStringToUCS4String
  • VarToWideStr
  • VarToWideStrDef
The following routines work directly with WideStrings:
  • WideCompareStr
  • WideCompareText
  • WideSameStr
  • WideSameText
  • WideFmtStr
  • WideFormat
  • WideLowerCase
  • WideUpperCase
Finally, some routines include overloads for working with wide strings:
  • UniqueString
  • Length
  • Trim
  • TrimLeft
  • TrimRight

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!