Trimming multiple characters from a string
Top  Previous  Next


This is the same as the TrimAllChar() function, but can delete a set of characters from a string. See the comment for an example of the usage. Thanks to Jeff Hamblin <jphamblin@home.net> for this code.

type
  TDelChars = set of Char;

function DeleteCharsFromString(const TempStr: string; DelChars: TDelChars): string;
{ func to delete all occurrences of each char in a set from a string. }
{ e.g. DeleteCharsFromString('$12,345.67', ['$', ',']) will return '12345.67' } 
{ Thanks to Jeff Hamblin for this code. Email: jphamblin@home.net }
{ Web: http://www.qtools.com }

var
  i: integer;
begin
  Result := TempStr;
  for i := Length(result) downto 1 do
    if Result[i] in DelChars then
  Delete(result, i, 1);
end;


Blue Orb Software

support@blueorbsoft.com