EF.StrUtils
Routines
function RightPos(const ASubString, AString: string): Integer;Returns the index of the last occurrence of ASubString in AString. Returns 0 if ASubString is not contained in AString.
function StripPrefixAndSuffix(const AString, APrefix, ASuffix: string): string;Strips APrefix from the beginning of AString and ASuffix from the end of it, if found. Returns the stripped string. If a prefix or suffix isn't found, then that part of the input string is returned unchanged. The match is case insensitive. Passing '' in APrefix or ASuffix suppresses stripping of that part.
function StripPrefix(const AString, APrefix: string): string;Strips APrefix from the beginning of AString, if found. Returns the stripped string. If a prefix isn't found, then the input string is returned unchanged. The match is case insensitive.
function StripSuffix(const AString, ASuffix: string): string;Strips ASuffix from the end of AString, if found. Returns the stripped string. If a suffix isn't found, then the input string is returned unchanged. The match is case insensitive.
function GetRandomString(const ALength: Integer;Generates a random string of ALength characters in the 'A'..'Z' and '0'..'9' printable sets. Excludes the specified characters. The characters come from the operating system's cryptographic random source, not from the RTL's Random: this feeds password generation.
function GetRandomStringEx(const ALength: Integer;Generates a random string of ALength characters in the 'A'..'Z' and 'a'..'z' and '0'..'9' printable sets. Excludes the specified characters.
function GetRandomChar(const AChars: string): Char;One character of AChars, chosen uniformly from the operating system's cryptographic random source. Raises if AChars is empty.
function StrMatches(const AString, APattern: string): Boolean;Returns True if APattern matches AString. APattern may contain the following jolly characters: ? matches any one character. * matches any sequence of zero or more characters. Everything else is compared literally in a case sensitive manner.
function StrMatchesEx(const AString, APattern: string): Boolean;Interprets a ~ character at the beginning of a pattern as a negation symbol. Otherwise it's identical to StrMatches.
function StripJollyCharacters(const AString: string): string;Strips any jolly characters used by StrMatches and StrMatchesEx from AString.
function CountSubstrings(const AString, ASubstring: string): Integer;Returns the number of occurences of ASubstring in AString.
function MatchStr(const AString: string;Returns True if AString equals at least one of AStrings, False otherwise. Wraps IndexStr, not present in all supported Delphi versions.
function CreateCompactGuidStr: string;Creates a new GUID and returns it as a string in a compact format (32 chars).
function CreateGuidStr: string;Creates a new GUID and returns it as a string.
function FetchStr(var AString, ASubstring: string;Strips and returns (in ASubstring) the initial part of AString until ASeparator, or until the end of the string if ASeparator is not found. If ARemoveSeparator is True, then the separator is stripped from AString as well (but not included in the returned string anyway). The function returns True ultil it has reached the end of AString. When the function returns False, AString is always '', while ASubstring may or may not be ''.
function WordPos(const AWord, AString: string): Integer;Works like Pos, except that it returns 0 if ASubString is not part of AString as a whole word.
This function is case insensitive.
function WordPos(const AWords: array of string;Calls the other version of WordPos for each item in AWords. Returns a value <> 0 the first time that WordPos returns a value <> 0, otherwise returns 0.
This function is case insensitive.
function PadRight(const AString: string;If AString is shorter than AFinalLength characters, adds instances of PadCharacter to the right of the string until it is long exactly AFinalLength characters. If AString is long exactly AFinalLength characters, it is returned unchanged. If AString is longer than AFinalLength characters, an exception is raised.
function PadLeft(const AString: string;If AString is shorter than AFinalLength characters, adds instances of PadCharacter to the left of the string until it is long exactly AFinalLength characters. If AString is long exactly AFinalLength characters, it is returned unchanged. If AString is longer than AFinalLength characters, an exception is raised.
function TextFileToString(const AFileName: string;Reads a text file and returns the content.
procedure StringToTextFile(const AString, AFileName: string;Writes AString to a text file.
procedure AppendStringToTextFile(const AString, AFileName: string;Appends AString to an existing text file. If the file doesn't exist, works like StringToTextFile.
function Camelize(const AString: string): string;Turns the first character of each word in AString to upper case, and each other character to lower case. Words are separated by spaces.
function UpperUnderscoreToSpaced(const AString: string): string;Converts 'THIS_IS_A_STRING' to 'THIS IS A STRING'.
function UpperUnderscoreToCamel(const AString: string): string;Converts 'THIS_IS_A_STRING' to 'ThisIsAString'.
function CamelToUpperUnderscore(const AString: string): string;Converts 'ThisIsAString' to 'THIS_IS_A_STRING'.
function CamelToSpaced(const AString: string): string;Converts 'ThisIsAString' to 'This Is A String'.
function FirstLowerCase(const AString: string): string;Converts the first character of AString to lower case.
function MakePlural(const ASingularName: string): string;Tries to make the plural form of a specified singular name acoording to the rules of the english language.
function GetIndexOfValue(const AStrings: TStrings;Returns the index of AValue in AStrings, which contains name=value pairs.
function InsertStr(const ASubstring, AString: string;Inserts ASubstring into AString at the specified position and returns the resulting string.
function CountLeading(const AString: string;Returns the count of uninterrupted leading AChars in AString. Returns 0 if AString does not begin with AChar.
function TabsToSpaces(const AString: string;Converts all tab characters (#9) in AString with sequences of ASpacesPerTab spaces, and returns the resulting string.
function StringInCommaList(const AString, ACommaList: string): Boolean;Returns True if AString equals one of the strings in the specified comma-separated list, and False otherwise.
function CommaListItemCount(const ACommaList: string): Integer;Returns the number of items in ACommaList.
function SmartConcat(const ATerm1, AConcatString, ATerm2: string): string;Returns ATerm1 + AConcatString + ATerm2. If either Term1 or Term2 is empty, returns the other non-empty term without adding AConcatString. If both ATerm1 and ATerm2 are empty, returns an empty string.
function FirstDifferent(const AValues: array of string;Returns the first value in AValues that's different from AValue. If all values in AValues are equal to AValue, then the function returns AValue.
function GetStringHash(const AString: string): string;Returns the MD5 hash of AString, encoded as a sequence of lower-case hex values. The resulting string holds 32 hex digits, corresponding to 16 bytes.
function Split(const AString: string;Splits the specified string based on the specified separator characters and returns an array with the splitted elements.
Parameters:
ASeparators— One or more separator characters.
function Join(const AStrings: TStringDynArray;Joins the elements in the specified array with the specified separator and returns the resulting string.
function SplitPairs(const AString: string;Splits the specified string based on the specified separator characters and returns an array of pairs with the splitted elements, assuming the strings are in pair (name=value) format.
function JoinPairs(const APairs: TEFPairs;Joins the pairs producing a string with a list of name=value pairs separated by the specified separator.
function FormatByteSize(const AByteSize: Longint;Formats the specified number of bytes in GBs, MBs, KBs or bytes according to the size.
FormatByteSize(2560) yields '2.5 KBs'function FirstDelimiter(const ADelimiters, AString: string;The opposite of RTL's LastDelimiter function. Returns the index of the first occurence in a string of one of the specified characters. If none of the characters in ADelimiters appear in the string S, the function returns 0.
procedure ReplaceAllCaseSensitive(var AString: string;A faster replacement for StringReplace ONLY FOR CASE_SENSITIVE comparisons. Up to 15 times faster in such cases.
function MatchWildCards(const AFileName: string;Check form AFileName is compatible with WildCards AAcceptedWildCards is a string with a list of wildcards eg: .xls .xlsx
function ValidFileName(const FileName : string;Returns a Valid filename: if and invalid char was present into string it's replaced with ValidChar ('_' by default) If SpaceIsValid is False also spaces are replaced
