Sub String Stuff 

www.madshi.net

To check how many sub strings a string contains, you can use the following function:

function SubStrCount (str: string; delimiter: char = '|') : integer;

// Examples:
SubStrCount(''          )  ->  0
SubStrCount(' '         )  ->  1
SubStrCount('1|2|3'     )  ->  3
SubStrCount('1,2,3'     )  ->  1
SubStrCount('1,2,3', ',')  ->  3

The function "SubStr" returns the specified sub string. The first sub string has the index 1.

function SubStr (str: string; index: cardinal; delimiter: char = '|') : string;

// Examples:
SubStr('1|2|3', 1     )  ->  '1'
SubStr('1,2,3', 1     )  ->  '1,2,3'
SubStr('1,2,3', 2     )  ->  ''
SubStr('1,2,3', 3, ',')  ->  '3'

The following functions check whether a specified sub string exists. "SubStrExists" checks that case sensitively, "SubTextExists" checks case insensitively.

function SubStrExists  (str: string; subStr : string; delimiter: char = '|') : boolean;
function SubTextExists (str: string; subText: string; delimiter: char = '|') : boolean;

// Examples:
SubStrExsts ('Dog;Cat;Mouse', 'Dog', ';')  ->  true
SubStrExsts ('Dog;Cat;Mouse', 'dog', ';')  ->  false
SubTextExsts('Dog;Cat;Mouse', 'dog', ';')  ->  true

The function "FormatSubStrs" deletes all leading and trailing control characters and spaces from each sub string and then removes all empty sub strings:

procedure FormatSubStrs (var str: string; delimiter: char = '|');

// Examples:
FormatSubStr('||| |1||2| ')  ->  '1|2'