Skip to content

TStringHelper

[Properties (by Name)][Methods (by Name)][Events (by Name)]

Helper type for strings.

Declaration

Source position: syshelph.inc line 60

Type
  TStringHelper = type helper type for AnsiString
  private
    function GetChar(AIndex: SizeInt) : Char;
    function GetLength : SizeInt;
  public
    Empty = '';
    class function Compare(const A: string; const B: string) : Integer
                          ;  Overload;  Static;
    class function Compare(const A: string; const B: string; 
                          IgnoreCase: Boolean) : Integer;  Overload;  Static;
    class function Compare(const A: string; const B: string; 
                          Options: TCompareOptions) : Integer;  Overload
                          ;  Static;
    class function Compare(const A: string; IndexA: SizeInt; 
                          const B: string; IndexB: SizeInt; ALen: SizeInt)
                           : Integer;  Overload;  Static;
    class function Compare(const A: string; IndexA: SizeInt; 
                          const B: string; IndexB: SizeInt; ALen: SizeInt; 
                          IgnoreCase: Boolean) : Integer;  Overload;  Static;
    class function Compare(const A: string; IndexA: SizeInt; 
                          const B: string; IndexB: SizeInt; ALen: SizeInt; 
                          Options: TCompareOptions) : Integer;  Overload
                          ;  Static;
    class function CompareOrdinal(const A: string; const B: string)
                                  : Integer;  Overload;  Static;
    class function CompareOrdinal(const A: string; IndexA: SizeInt; 
                                 const B: string; IndexB: SizeInt; 
                                 ALen: SizeInt) : Integer;  Overload
                                 ;  Static;
    class function CompareText(const A: string; const B: string) : Integer
                              ;  Static;
    class function Copy(const Str: string) : string;  Static;
    class function Create(AChar: Char; ACount: SizeInt) : string;  Overload
                         ;  Static;
    class function Create(const AValue: Array of Char) : string;  Overload
                         ;  Static;
    class function Create(const AValue: Array of Char; StartIndex: SizeInt; 
                         ALen: SizeInt) : string;  Overload;  Static;
    class function EndsText(const ASubText: string; const AText: string)
                            : Boolean;  Static;
    class function Equals(const a: string; const b: string) : Boolean
                         ;  Overload;  Static;
    function Equals(const AValue: string) : Boolean;  Overload;
    class function Format(const AFormat: string; const args: Array of const)
                          : string;  Overload;  Static;
    function Format(const args: Array of const) : string;  Overload;
    class function IsNullOrEmpty(const AValue: string) : Boolean;  Static;
    class function IsNullOrWhiteSpace(const AValue: string) : Boolean
                                     ;  Static;
    class function Join(const Separator: string; 
                       const Values: Array of const) : string;  Overload
                       ;  Static;
    class function Join(const Separator: string; 
                       const Values: Array of string) : string;  Overload
                       ;  Static;
    class function Join(const Separator: string; 
                       const Values: Array of string; StartIndex: SizeInt; 
                       ACount: SizeInt) : string;  Overload;  Static;
    class function LowerCase(const S: string) : string;  Overload;  Static;
    class function Parse(const AValue: Boolean) : string;  Overload;  Static;
    class function Parse(const AValue: Extended) : string;  Overload
                        ;  Static;
    class function Parse(const AValue: Int64) : string;  Overload;  Static;
    class function Parse(const AValue: Integer) : string;  Overload;  Static;
    class function ToBoolean(const S: string) : Boolean;  Overload;  Static;
    function ToBoolean : Boolean;  Overload;
    class function ToDouble(const S: string) : Double;  Overload;  Static;
    function ToDouble : Double;  Overload;
    class function ToExtended(const S: string) : Extended;  Overload
                             ;  Static;
    function ToExtended : Extended;  Overload;
    class function ToInt64(const S: string) : Int64;  Overload;  Static;
    function ToInt64 : Int64;  Overload;
    class function ToInteger(const S: string) : Integer;  Overload;  Static;
    function ToInteger : Integer;  Overload;
    class function ToSingle(const S: string) : Single;  Overload;  Static;
    function ToSingle : Single;  Overload;
    class function UpperCase(const S: string) : string;  Overload;  Static;
    function CompareTo(const B: string) : Integer;
    function Contains(const AValue: string) : Boolean;
    procedure CopyTo(SourceIndex: SizeInt; var destination: Array of Char; 
                    DestinationIndex: SizeInt; ACount: SizeInt);
    function CountChar(const C: Char) : SizeInt;
    function DeQuotedString : string;  Overload;
    function DeQuotedString(const AQuoteChar: Char) : string;  Overload;
    function EndsWith(const AValue: string) : Boolean;  Overload;
    function EndsWith(const AValue: string; IgnoreCase: Boolean) : Boolean
                     ;  Overload;
    function GetHashCode : Integer;
    function IndexOf(AValue: Char) : SizeInt;  Overload;
    function IndexOf(const AValue: string) : SizeInt;  Overload;
    function IndexOf(AValue: Char; StartIndex: SizeInt) : SizeInt;  Overload;
    function IndexOf(const AValue: string; StartIndex: SizeInt) : SizeInt
                    ;  Overload;
    function IndexOf(AValue: Char; StartIndex: SizeInt; ACount: SizeInt)
                     : SizeInt;  Overload;
    function IndexOf(const AValue: string; StartIndex: SizeInt; 
                    ACount: SizeInt) : SizeInt;  Overload;
    function IndexOfUnQuoted(const AValue: string; StartQuote: Char; 
                            EndQuote: Char; StartIndex: SizeInt) : SizeInt
                            ;  Overload;
    function IndexOfAny(const AnyOf: Array of Char) : SizeInt;  Overload;
    function IndexOfAny(const AnyOf: Array of Char; StartIndex: SizeInt)
                        : SizeInt;  Overload;
    function IndexOfAny(const AnyOf: Array of Char; StartIndex: SizeInt; 
                       ACount: SizeInt) : SizeInt;  Overload;
    function IndexOfAny(const AnyOf: Array of string) : SizeInt;  Overload;
    function IndexOfAny(const AnyOf: Array of string; StartIndex: SizeInt)
                        : SizeInt;  Overload;
    function IndexOfAny(const AnyOf: Array of string; StartIndex: SizeInt; 
                       ACount: SizeInt) : SizeInt;  Overload;
    function IndexOfAny(const AnyOf: Array of string; StartIndex: SizeInt; 
                       ACount: SizeInt; out AMatch: SizeInt) : SizeInt
                       ;  Overload;
    function IndexOfAnyUnquoted(const AnyOf: Array of Char; 
                               StartQuote: Char; EndQuote: Char) : SizeInt
                               ;  Overload;
    function IndexOfAnyUnquoted(const AnyOf: Array of Char; 
                               StartQuote: Char; EndQuote: Char; 
                               StartIndex: SizeInt) : SizeInt;  Overload;
    function IndexOfAnyUnquoted(const AnyOf: Array of Char; 
                               StartQuote: Char; EndQuote: Char; 
                               StartIndex: SizeInt; ACount: SizeInt)
                                : SizeInt;  Overload;
    function IndexOfAnyUnquoted(const AnyOf: Array of string; 
                               StartQuote: Char; EndQuote: Char; 
                               StartIndex: SizeInt; out Matched: SizeInt)
                                : SizeInt;  Overload;
    function Insert(StartIndex: SizeInt; const AValue: string) : string;
    function IsDelimiter(const Delimiters: string; Index: SizeInt) : Boolean;
    function IsEmpty : Boolean;
    function LastDelimiter(const Delims: string) : SizeInt;
    function LastIndexOf(AValue: Char) : SizeInt;  Overload;
    function LastIndexOf(const AValue: string) : SizeInt;  Overload;
    function LastIndexOf(AValue: Char; AStartIndex: SizeInt) : SizeInt
                        ;  Overload;
    function LastIndexOf(const AValue: string; AStartIndex: SizeInt)
                         : SizeInt;  Overload;
    function LastIndexOf(AValue: Char; AStartIndex: SizeInt; 
                        ACount: SizeInt) : SizeInt;  Overload;
    function LastIndexOf(const AValue: string; AStartIndex: SizeInt; 
                        ACount: SizeInt) : SizeInt;  Overload;
    function LastIndexOfAny(const AnyOf: Array of Char) : SizeInt;  Overload;
    function LastIndexOfAny(const AnyOf: Array of Char; 
                           AStartIndex: SizeInt) : SizeInt;  Overload;
    function LastIndexOfAny(const AnyOf: Array of Char; 
                           AStartIndex: SizeInt; ACount: SizeInt) : SizeInt
                           ;  Overload;
    function PadLeft(ATotalWidth: SizeInt) : string;  Overload;
    function PadLeft(ATotalWidth: SizeInt; PaddingChar: Char) : string
                    ;  Overload;
    function PadRight(ATotalWidth: SizeInt) : string;  Overload;
    function PadRight(ATotalWidth: SizeInt; PaddingChar: Char) : string
                     ;  Overload;
    function QuotedString : string;  Overload;
    function QuotedString(const AQuoteChar: Char) : string;  Overload;
    function Remove(StartIndex: SizeInt) : string;  Overload;
    function Remove(StartIndex: SizeInt; ACount: SizeInt) : string
                   ;  Overload;
    function Replace(OldChar: Char; NewChar: Char) : string;  Overload;
    function Replace(OldChar: Char; NewChar: Char; 
                    ReplaceFlags: TReplaceFlags) : string;  Overload;
    function Replace(const OldValue: string; const NewValue: string)
                     : string;  Overload;
    function Replace(const OldValue: string; const NewValue: string; 
                    ReplaceFlags: TReplaceFlags) : string;  Overload;
    function Split(const Separators: Array of Char) : TStringArray
                  ;  Overload;
    function Split(const Separators: Array of Char; ACount: SizeInt)
                   : TStringArray;  Overload;
    function Split(const Separators: Array of Char; 
                  Options: TStringSplitOptions) : TStringArray;  Overload;
    function Split(const Separators: Array of Char; ACount: SizeInt; 
                  Options: TStringSplitOptions) : TStringArray;  Overload;
    function Split(const Separators: Array of string) : TStringArray
                  ;  Overload;
    function Split(const Separators: Array of string; ACount: SizeInt)
                   : TStringArray;  Overload;
    function Split(const Separators: Array of string; 
                  Options: TStringSplitOptions) : TStringArray;  Overload;
    function Split(const Separators: Array of string; ACount: SizeInt; 
                  Options: TStringSplitOptions) : TStringArray;  Overload;
    function Split(const Separators: Array of Char; AQuote: Char)
                   : TStringArray;  Overload;
    function Split(const Separators: Array of Char; AQuoteStart: Char; 
                  AQuoteEnd: Char) : TStringArray;  Overload;
    function Split(const Separators: Array of Char; AQuoteStart: Char; 
                  AQuoteEnd: Char; Options: TStringSplitOptions)
                   : TStringArray;  Overload;
    function Split(const Separators: Array of Char; AQuoteStart: Char; 
                  AQuoteEnd: Char; ACount: SizeInt) : TStringArray
                  ;  Overload;
    function Split(const Separators: Array of Char; AQuoteStart: Char; 
                  AQuoteEnd: Char; ACount: SizeInt; 
                  Options: TStringSplitOptions) : TStringArray;  Overload;
    function Split(const Separators: Array of string; AQuote: Char)
                   : TStringArray;  Overload;
    function Split(const Separators: Array of string; AQuoteStart: Char; 
                  AQuoteEnd: Char) : TStringArray;  Overload;
    function Split(const Separators: Array of string; AQuoteStart: Char; 
                  AQuoteEnd: Char; Options: TStringSplitOptions)
                   : TStringArray;  Overload;
    function Split(const Separators: Array of string; AQuoteStart: Char; 
                  AQuoteEnd: Char; ACount: SizeInt) : TStringArray
                  ;  Overload;
    function Split(const Separators: Array of string; AQuoteStart: Char; 
                  AQuoteEnd: Char; ACount: SizeInt; 
                  Options: TStringSplitOptions) : TStringArray;  Overload;
    function StartsWith(const AValue: string) : Boolean;  Overload;
    function StartsWith(const AValue: string; IgnoreCase: Boolean) : Boolean
                       ;  Overload;
    function Substring(AStartIndex: SizeInt) : string;  Overload;
    function Substring(AStartIndex: SizeInt; ALen: SizeInt) : string
                      ;  Overload;
    function ToCharArray : TCharArray;  Overload;
    function ToCharArray(AStartIndex: SizeInt; ALen: SizeInt) : TCharArray
                        ;  Overload;
    function ToLower : string;  Overload;
    function ToLowerInvariant : string;
    function ToUpper : string;  Overload;
    function ToUpperInvariant : string;
    function Trim : string;  Overload;
    function Trim(const ATrimChars: Array of Char) : string;  Overload;
    function TrimLeft : string;  Overload;
    function TrimLeft(const ATrimChars: Array of Char) : string;  Overload;
    function TrimRight : string;  Overload;
    function TrimRight(const ATrimChars: Array of Char) : string;  Overload;
    function TrimEnd(const ATrimChars: Array of Char) : string;
    function TrimStart(const ATrimChars: Array of Char) : string;
    Chars[AIndex: SizeInt]: Char;
    &Length : SizeInt;
  end
  ;

Description

TStringHelper adds various helper routines to the string type. These are mostly conversion routines, and some formatting routines.

For similarity to C-like languages, all the indexes in these helper routines are zero based.

Members

Member Type Visibility Description
Chars Property public Zero-based Indexed access to the characters in the string.
Compare Method public Compare 2 strings
CompareOrdinal Method public Compare 2 strings byte for byte
CompareText Method public Compare 2 strings case insensitively.
CompareTo Method public Compare string to another
Contains Method public Check is the string contains another
Copy Method public Return a unique copy of a string
CopyTo Method public Copy part of the string to an array of characters
CountChar Method public Count the occurrences of a character
Create Method public Create a new string
DeQuotedString Method public Return a dequoted version of the string
Empty Constant public Check if the string is empty
EndsText Method public Check if one string is the ending of another.
EndsWith Method public Check if the string is ended by another.
Equals Method public Check if 2 strings are equal
Format Method public Format a string using provided arguments.
GetChar Method private
GetHashCode Method public Get a hash code for the string
GetLength Method private
IndexOf Method public Find the position (index) of a string or character
IndexOfAny Method public Find the position (index) of any string or character in a list.
IndexOfAnyUnquoted Method public Find the position (index) of any string or character in a list.
IndexOfUnQuoted Method public Index of string, skipping quoted parts.
Insert Method public Insert a string at a given position
IsDelimiter Method public Check whether a character at a given position is a delimiter
IsEmpty Method public Check whether the string is empty.
IsNullOrEmpty Method public Check if a string is empty
IsNullOrWhiteSpace Method public Check if a string is empty or contains only whitespace characters.
Join Method public Join a series of strings, separated using a given separator
LastDelimiter Method public Return the last position of one of a series of delimiters
LastIndexOf Method public Find the last position (index) of a string or character
LastIndexOfAny Method public Find the last position (index) of any string or character in a list.
Length Property public Return the length of the string
LowerCase Method public Return the lowercase version of a string.
PadLeft Method public Pad the string on the left with an indicated character
PadRight Method public Pad the string on the right with an indicated character
Parse Method public Return a string representation of the argument
QuotedString Method public Return a quoted version of the string
Remove Method public Remove a number of characters from the string
Replace Method public Replace occurrences of one string with another.
Split Method public Split a string in a number of parts
StartsWith Method public Check if one string starts with another
Substring Method public Return a part of the string
ToBoolean Method public Convert string to boolean
ToCharArray Method public Return the string as an array of characters.
ToDouble Method public Convert string to double-sized floating point value
ToExtended Method public Convert string to extended-sized floating point value
ToInt64 Method public Convert string to 64-bit signed integer
ToInteger Method public Convert string to 32-bit signed integer
ToLower Method public Convert to lowercase
ToLowerInvariant Method public Convert to lowercase
ToSingle Method public Convert string to single-sized floating point value
ToUpper Method public Convert to uppercase.
ToUpperInvariant Method public Convert to uppercase
Trim Method public Strips a set of trim characters from the beginning and end of the string.
TrimEnd Method public Alias for TrimRight
TrimLeft Method public Strips a set of trim characters from the beginning of the string.
TrimRight Method public Strips a set of trim characters from the end of the string.
TrimStart Method public Alias for TrimLeft
UpperCase Method public Return uppercase version of a string

Inheritance

Class Description
TStringHelper Helper type for strings.

See also

Name Description
Char Character type (1 byte)
SizeInt Signed integer type which fits for sizes
TGUIDHelper Helper type for TGUID