unit stringUtils

String manipulation library.

author: dely daniel.kozminski@gmail.com


String manipulation procedures and functions for use with MadPascal.
https://gitlab.com/delysio/mad-pascal

Interface:

name:description:
strInsert

procedure strInsert(var s: string; var s2: string; index: byte);


Insert one string in another.
    parameters:
  • (string) s - The input string.
  • (string) s2 - String to insert.
  • (byte) index - Position to insert.
strDelete

procedure strDelete(var s: string; index: byte; count: byte);


Removes Count characters from string S, starting at position Index.
    parameters:
  • (string) s - The input string.
  • (byte) index - Position.
  • (byte) count - Number of chars to remove.
strCat

function strCat(s1: string; s2: string): string; overload;


Returns concatenated strings.
    parameters:
  • (string) s1 - The input string.
  • (string) s2 - The string to concatenate.
  • returns:
  • (string) - Concatenated string.
strCat

function strCat(s: string; c: char): string; overload;


Returns concatenated strings.
    parameters:
  • (string) s - The input string.
  • (char) c - The char to concatenate.
  • returns:
  • (string) - Concatenated string.
strAdd

procedure strAdd(var s: string; c: char); overload;


Adds char to string.
    parameters:
  • (string) s - The input string.
  • (char) c - Char to add.
strAdd

procedure strAdd(var s1: string; s2: string); overload;


Adds string to string.
    parameters:
  • (string) s1 - The input string.
  • (string) s2 - The string to add.
strLeft

function strLeft(s: string; count: byte): string;


Returns left portion of string specified by the count parameter.
    parameters:
  • (string) s - The input string.
  • (byte) count - How many characters will be returned.
  • returns:
  • (string) - the returned string will end at the count position in string, counting from one.
strRight

function strRight(s: string; count: byte): string;


Returns right portion of string specified by the count parameter.
    parameters:
  • (string) s - The input string.
  • (byte) count - How many characters will be returned.
  • returns:
  • (string) - the returned string will start at the count position in string, counting from one.
strMid

function strMid(s: string; startChar: byte; countChars: byte): string;


Returns the portion of string specified by the startChar and countChars parameters.
    parameters:
  • (string) s - The input string.
  • (byte) startChar - start character index counting from one.
  • (byte) countChars - How many characters will be returned.
  • returns:
  • (string) - the returned string will start at the startChar position in string, counting from one and will consist of countChars chars.
strPos

function strPos(c: char; s: string): byte; overload;


Returns the first index of char in string
    parameters:
  • (string) c - char / needle.
  • (string) s - String / haystack.
  • returns:
  • (byte) - returns first index or 0 if substring was not found
strPos

function strPos(s1: string; s2: string): byte; overload;


Returns the first index of substring in string
    parameters:
  • (string) s1 - Substring / needle.
  • (string) s2 - String / haystack.
  • returns:
  • (byte) - returns first index or 0 if substring was not found
strLastPos

function strLastPos(s1: string; s2: string): byte;


Returns the last index of substring in string
    parameters:
  • (string) s1 - Substring / needle.
  • (string) s2 - String / haystack.
  • returns:
  • (byte) - returns last index or 0 if substring was not found
strIsPrefix

function strIsPrefix(s: string; p: string): boolean;


Returns information whether the first chars of the strings are the same
    parameters:
  • (string) s1 - String.
  • (string) s2 - Prefix.
  • returns:
  • (byte) - returns true or false
strReplace

function strReplace(s: string; c: char; rpl: char): string; overload;


Replace first occurrence of the search char (c) with the replacement char (rpl) This function is case-sensitive. Use strIReplace for case-insensitive replace.
    parameters:
  • (string) s - String / haystack.
  • (char) c - Char to find / needle.
  • (char) rpl - Replacement.
  • returns:
  • (string) - replaced string
strReplace

function strReplace(s1: string; s2: string; c: char): string; overload;


Replace first occurrence of the search string (s2) with the replacement char (c) This function is case-sensitive. Use strIReplace for case-insensitive replace.
    parameters:
  • (string) s1 - String / haystack.
  • (string) s2 - String to find / needle.
  • (char) c - Replacement.
  • returns:
  • (string) - replaced string
strReplace

function strReplace(s1: string; s2: string; s3: string): string; overload;


Replace first occurrence of the search string (s2) with the replacement string (s3) This function is case-sensitive. Use strIReplace for case-insensitive replace.
    parameters:
  • (string) s1 - String / haystack.
  • (string) s2 - String to find / needle.
  • (string) s3 - Replacement.
  • returns:
  • (string) - replaced string
strIReplace

function strIReplace(s: string; c: char; rpl: char): string;


Replace first occurrence of the search char (c) with the replacement char (rpl) This function is Case-insensitive. Use strReplace for case-sensitive replace.
    parameters:
  • (string) s - String / haystack.
  • (char) c - char to find / needle.
  • (char) rpl - replacement.
  • returns:
  • (string) - replaced string
strReplaceAll

function strReplaceAll(s: string; c: char; rpl: char): string; overload;


Replace all occurrences of the search char (c) with the replacement char (rpl) This function is case-sensitive. Use strIReplace for case-insensitive replace.
    parameters:
  • (string) s - String / haystack.
  • (char) c - Char to find / needle.
  • (char) rpl - Replacement.
  • returns:
  • (string) - replaced string