Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to trim any character (or a substring) from a string?

I use C# basically. There I can do:

string trimmed = str.Trim('\t');

to trim tabulation from the string str and return the result to trimmed.

In delphi7 I found only Trim, that trims spaces.

How can I achieve the same functionality?

like image 852
horgh Avatar asked Nov 21 '12 04:11

horgh


1 Answers

There is string helper TStringHelper.Trim that accepts array of Char as optional parameter.

function Trim(const TrimChars: array of Char): string; overload;

So, you can use

trimmed := str.Trim([#09]);

for your example. #09 here is ASCII code for Tab character.

This function exists since at least Delphi XE3.

Hope it helps.

like image 85
vladon Avatar answered Oct 12 '22 22:10

vladon