Trim string with specific charset

delphi, delphi-xe

Solution

As far i know there is not exist a RTL function like that. But you can check the `JclStrings` unit part of the JCL project , which include the `StrTrimCharsLeft` and `StrTrimCharsRight` functions.

function StrTrimCharsLeft(const S: string; const Chars: TCharValidator): string; overload;
function StrTrimCharsLeft(const S: string; const Chars: array of Char): string; overload;
function StrTrimCharRight(const S: string; C: Char): string;
function StrTrimCharsRight(const S: string; const Chars: TCharValidator): string; overload;
function StrTrimCharsRight(const S: string; const Chars: array of Char): string; overload;

Problem

Is there a function in Delphi equivalent to Cocoa's `stringByTrimmingCharactersInSet`? What I need is to eliminate all the characters included in a charset that are found at the beginning or the end of a string. There can be none, one or more starting or ending the string... What would be the most efficient way to do this in Delphi?

Original source