Download Now

    Reference StringHelper

    Declared in Codebot.System.pas on line 521

    StringHelper adds methods and properties to the string type
      StringHelper = record helper for string
      public
        { Convert to a string representation }
        function ToString: string;
        { Make a string unique, reducing its reference count to one }
        procedure Unique;
        { Repeat a character a given length into the string }
        procedure CharInto(C: Char; Len: Integer);
        { Copy a memory buffer into string }
        procedure CopyInto(P: Pointer; Len: Integer);
        { Inserts a substring at a position into string }
        procedure InsertInto(const SubStr: string; Position: Integer);
        { Returns true if a string matches a case insensitive value }
        function Equals(const Value: string; IgnoreCase: Boolean = False): Boolean; overload;
        { Returns true if a string matches any in a set of case insensitive values }
        function Equals(const Values: array of string; IgnoreCase: Boolean = False): Boolean; overload;
        { Compares two strings optionally ignoring case returning -1 if string comes
          before value, 1 if string comes after value, or 0 if string and value are
          equal }
        function Compare(const Value: string; IgnoreCase: Boolean = False): Integer;
        { Convert a string to uppercase }
        function ToUpper: string;
        { Convert a string to lowercase }
        function ToLower: string;
        { Copies a substring given a start and length }
        function Copy(Start: Integer; Len: Integer = 0): string;
        { Insert a substring given a start and length }
        function Insert(const SubStr: string; Position: Integer): string;
        { Searches a string for a substring optionally ignoring case }
        function IndexOf(const SubStr: string; IgnoreCase: Boolean = False): Integer; overload;
        { Searches a string for a substring from a start position optionally
          ignoring case }
        function IndexOf(const SubStr: string; Start: Integer; IgnoreCase: Boolean = False): Integer; overload;
        { Returns the number of a substring matches within a string }
        function MatchCount(const SubStr: string; IgnoreCase: Boolean = False): Integer;
        { Returns an array of indices of a substring matches within a string }
        function Matches(const SubStr: string; IgnoreCase: Boolean = False): IntArray;
        { Removes the last occurrence of a substring }
        function RemoveLast(const SubStr: string; IgnoreCase: Boolean = False): string;
        { Replaces every instance of a pattern in a string }
        function Replace(const OldPattern, NewPattern: string; IgnoreCase: Boolean = False): string;
        { Replaces the first instance of a pattern in a string }
        function ReplaceOne(const OldPattern, NewPattern: string; IgnoreCase: Boolean = False): string;
        { Replaces everything after the first instance of a pattern in a string }
        function ReplaceAfter(const OldPattern, NewPattern: string; IgnoreCase: Boolean = False): string;
        { Trims white space from both sides of a string }
        function Trim: string;
        { Returns the index of a string in a string array or -1 if there is no match }
        function ArrayIndex(const Values: array of string): Integer;
        { Break a string into lines separated by the break style }
        function Lines: StringArray;
        { Returns the first entire line containing SubStr }
        function LineWith(const SubStr: string; IgnoreCase: Boolean = False): string;
        { Splits a string into a string array using a separator }
        function Split(Separator: string): StringArray;
        { Splits a string into a int array using a separator }
        function SplitInt(const Separator: string): IntArray;
        { Splits a string into a int64 array using a separator }
        function SplitInt64(const Separator: string): Int64Array;
        { Splits a string into a series of tokens }
        function SplitTokens: StringArray;
        { Splits a string into words separated by whitespace optionally wrapping at
          a maximum number of columns }
        function Words(MaxColumns: Integer = 0): StringArray;
        { Returns the first subsection of a string if it were split using a
          separator }
        function FirstOf(const Separator: string): string;
        { Returns the second subsection of a string if it were split using a
          separator }
        function SecondOf(const Separator: string): string;
        { Returns the last subsection of a string if it were split using a separator }
        function LastOf(const Separator: string): string;
        { Returns the text exclusive between markers A and B }
        function Between(const MarkerA, MarkerB: string): string;
        { Search a string for a substring optionally ignoring case }
        function Contains(const SubStr: string; IgnoreCase: Boolean = False): Boolean;
        { Returns true if a string begins with a substring while optionally ignoring
          case }
        function BeginsWith(const SubStr: string; IgnoreCase: Boolean = False): Boolean; overload;
        { Returns true if a string begins with any substring while optionally
          ignoring case }
        function BeginsWith(const SubStrs: StringArray; IgnoreCase: Boolean = False): Boolean; overload;
        { Returns true if a string end with a substring while optionally ignoring
          case }
        function EndsWith(const SubStr: string; IgnoreCase: Boolean = False): Boolean; overload;
        { Returns true if a string end with any substring while optionally ignoring
          case }
        function EndsWith(const SubStrs: StringArray; IgnoreCase: Boolean = False): Boolean; overload;
        { Returns a string made to fit a given length padded on the left with a
          character }
        function PadLeft(C: Char; Len: Integer): string;
        { Returns a string made to fit a given length padded on the right with a
          character }
        function PadRight(C: Char; Len: Integer): string;
        { Returns a string surrounded by quotes if it contains whitespace }
        function Quote: string;
        { Formats a series of arguments into a string }
        function Format(Args: array of const): string;
        { Analyze a string and find its line break style }
        function LineBreakStyle: TTextLineBreakStyle;
        { Converts the line break style of a string to the desired style }
        function AdjustLineBreaks(Style: TTextLineBreakStyle): string; overload;
        { Converts the line break style of a string to the system preferred defined
          style }
        function AdjustLineBreaks: string; overload;
        { Gets true if a string has a length of zero }
        property IsEmpty: Boolean read GetIsEmpty;
        { Gets true if a string contains only whitespace characters }
        property IsWhitespace: Boolean read GetIsWhitespace;
        { Gets true if a string matches to rules of an identifier }
        property IsIdentifier: Boolean read GetIsIdentifier;
        { Gets true if a string matches to rules of an attribute }
        property IsAttribute: Boolean read GetIsAttribute;
        { Gets or sets the length allocated for the string }
        property Length: Integer read GetLength write SetLength;
      end;