String Deletion

The following functions are some variations around the "System.Delete" function. The "Ret*" functions return the changed string instead of changing the input parameter. The "*DeleteR" functions delete the last "count" characters of the string.

function RetDelete  (const str : string;
                     index     : cardinal;
                     count     : cardinal = maxCard) : string;
function RetDeleteR (const str : string;
                     count     : cardinal) : string;
procedure   DeleteR (var   str : string;
                     count     : cardinal);

// Example:
DeleteR('test123', 3)  ->  'test'

The Trim functions delete all control and space characters at the end and the beginning of the string.

procedure   TrimStr (  var str: string);
function RetTrimStr (const str: string) : string;

The KillChar(s) functions delete all specified characters from the string. If at least one character was deleted, the result is true.

function KillChar  (var str: string; killChr :   char) : boolean;
function KillChars (var str: string; killChrs: TSChar) : boolean;

// Examples:
KillChar ('This is a little test...', 'u'       )  ->  'This is a little test...' / false
KillChar ('This is a little test...', 'e'       )  ->  'This is a littl tst...'   / true
KillChars('This is a little test...', ['e', '.'])  ->  'This is a littl tst'      / true

The following function deletes "killStr" completely from the string. If "killStr" was found at least one time, the result is true.

function KillStr (var str: string; killStr: string) : boolean;

// Examples:
KillStr('This test is a little test.', 'fun'  )  ->  'This test is a little test.' / false
KillStr('This test is a little test.', ' test')  ->  'This is a little.'           / true