RAD Studio
ContentsIndex
PreviousUpNext
Commonly Used Long String Routines

The string handling routines in SysUtils handle both UnicodeString and AnsiString types. Within their functional areas, some routines are used for the same purpose, the differences being whether they use a particular criterion in their calculations. 

The AnsiStrings unit's functions offer the same capabilities as the SysUtils unit's routines. AnsiStrings functions provide better performance for AnsiString than SysUtils functions, because SysUtils functions convert an AnsiString to a UnicodeString. AnsiStrings functions work only with AnsiString, so there is no conversion. 

The following tables list these routines by these functional areas:

  • Comparison
  • Case conversion
  • Modification
  • Sub-string
Where appropriate, the tables also provide columns indicating whether a routine satisfies the following criteria.
  • Uses case sensitivity: If locale settings are used, it determines the definition of case. If the routine does not use locale settings, analyses are based upon the ordinal values of the characters. If the routine is case-insensitive, there is a logical merging of upper and lower case characters that is determined by a predefined pattern.
  • Uses locale settings: Locale settings allow you to customize your application for specific locales, in particular, for Asian language environments. Most locale settings consider lowercase characters to be less than the corresponding uppercase characters. This is in contrast to ASCII order, in which lowercase characters are greater than uppercase characters. Routines that use the system locale are typically prefaced with Ansi (that is, AnsiXXX).
  • Supports the multi-byte character set (MBCS): MBCSs are used when writing code for far eastern locales. Multi-byte characters are represented by one or more character codes, so the length in bytes does not necessarily correspond to the length of the string. The routines that support MBCS parse one- and multibyte characters.
ByteType and StrByteType determine whether a particular byte is the lead byte of a multibyte character. Be careful when using multibyte characters not to truncate a string by cutting a character in half. Do not pass characters as a parameter to a function or procedure, since the size of a character cannot be predetermined. Pass, instead, a pointer to a to a character or string. For more information about MBCS, see Enabling Application Code

String length routines:

Routine 
Uses locale settings 
Supports MBCS 
Returns 
yes  
yes  
Number of elements in string. Does not account for MBCS or Unicode surrogate pair "characters".  
yes  
yes  
Number of bytes required to represent type or variable.  

Note that Length and SizeOf give different results for all strings except for short strings. SizeOf equals the number of bytes in a pointer, since non-short strings are pointers. 

String comparison routines:

Routine 
Case-sensitive 
Uses locale settings 
Supports MBCS 
AnsiStrings.AnsiCompareStr
SysUtils.AnsiCompareStr  
yes  
yes  
yes  
AnsiStrings.AnsiCompareText
SysUtils.AnsiCompareText  
no  
yes  
yes  
AnsiStrings.AnsiCompareFileName
SysUtils.AnsiCompareFileName  
no  
yes  
yes  
AnsiStrings.AnsiMatchStr
StrUtils.AnsiMatchStr  
yes  
yes  
yes  
AnsiStrings.AnsiMatchText
StrUtils.AnsiMatchText  
no  
yes  
yes  
AnsiStrings.AnsiContainsStr
StrUtils.AnsiContainsStr  
yes  
yes  
yes  
AnsiStrings.AnsiContainsText
StrUtils.AnsiContainsText  
no  
yes  
yes  
AnsiStrings.AnsiStartsStr
StrUtils.AnsiStartsStr  
yes  
yes  
yes  
AnsiStrings.AnsiStartsText
StrUtils.AnsiStartsText  
no  
yes  
yes  
AnsiStrings.AnsiEndsStr
StrUtils.AnsiEndsStr  
yes  
yes  
yes  
AnsiStrings.AnsiEndsText
StrUtils.AnsiEndsText  
no  
yes  
yes  
AnsiStrings.AnsiEndsStr
StrUtils.AnsiEndsStr  
yes  
yes  
yes  
AnsiStrings.AnsiIndexText
StrUtils.AnsiIndexText  
no  
yes  
yes  
AnsiStrings.CompareStr
SysUtils.CompareStr  
yes  
no  
no  
AnsiStrings.CompareText
SysUtils.CompareText  
no  
no  
no  
no  
no  
no  

Case conversion routines:

Routine 
Uses locale settings 
Supports MBCS 
AnsiStrings.AnsiLowerCase
SysUtils.AnsiLowerCase  
yes  
yes  
AnsiStrings.AnsiUpperCaseFileName
SysUtils.AnsiUpperCaseFileName  
yes  
yes  
AnsiStrings.AnsiUpperCase
SysUtils.AnsiUpperCase  
yes  
yes  
AnsiStrings.LowerCase
SysUtils.LowerCase  
no  
no. Works for A to Z only, not European accented characters.  
AnsiStrings.UpperCase
SysUtils.UpperCase  
no  
no. Works for a to z only, not European accented characters.  

Note: The routines used for string file names: AnsiCompareFileName, AnsiLowerCaseFileName, and AnsiUpperCaseFileName all use the system locale. You should always use file names that are portable because the locale (character set) used for file names can and might differ from the default user interface.
String modification routines:

Routine 
Case-sensitive 
Supports MBCS 
NA  
yes  
AnsiStrings.AnsiQuotedStr
SysUtils.AnsiQuotedStr  
NA  
yes  
AnsiStrings.AnsiReplaceStr
StrUtils.AnsiReplaceStr  
yes  
yes  
AnsiStrings.AnsiReplaceText
StrUtils.AnsiReplaceText  
no  
yes  
AnsiStrings.StringReplace
SysUtils.StringReplace  
optional by flag  
yes  
AnsiStrings.ReverseString
StrUtils.ReverseString  
NA  
no  
AnsiStrings.StuffString
StrUtils.StuffString  
NA  
no  
NA  
no  
yes  
yes  
AnsiStrings.Trim
SysUtils.Trim  
NA  
yes  
AnsiStrings.TrimLeft
SysUtils.TrimLeft  
NA  
yes  
AnsiStrings.TrimRight
SysUtils.TrimRight  
NA  
yes  
NA  
yes  

Sub-string routines:

Routine 
Case-sensitive 
Supports MBCS 
NA  
yes  
AnsiStrings.AnsiPos
SysUtils.AnsiPos  
yes  
yes  
AnsiStrings.IsDelimiter
SysUtils.IsDelimiter  
yes  
yes  
AnsiStrings.IsPathDelimiter
SysUtils.IsPathDelimiter  
yes  
yes  
AnsiStrings.LastDelimiter
SysUtils.LastDelimiter  
yes  
yes  
NA  
no  
NA  
no  
NA  
no  
AnsiStrings.QuotedStr
SysUtils.QuotedStr  
no  
no  
NA  
yes  

String information routines (in System):

Routine 
Returns 
System.StringCodePage  
Code page  
System.StringElementSize  
Element size  
System.StringRefCount  
Reference count  

Note: It is not safe to directly manipulate the internal structures of strings, since these change with product versions.

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