Link to home
Start Free TrialLog in
Avatar of poodle
poodle

asked on

Basic's Trim() function in Delphi 1.0?

I would like to know if there is a function like Basic's
Trim() to get rid of spaces in Delphi 1.0?
Avatar of ow
ow

 Hi poodle,

in unit sysutils you find:

{ Trim trims leading and trailing spaces and control characters from the  given string. }
function Trim(const S: string): string;

{ TrimLeft trims leading spaces and control characters from the given  string. }
function TrimLeft(const S: string): string;

{ TrimRight trims trailing spaces and control characters from the given  string. }
function TrimRight(const S: string): string;

regards
  ow

ow: that's correct for delphi >= 3 (2?), but not
for Delphi 1.

Here is the way to do it in Delphi1,2

as a procedure...

procedure Trim(var Str : string);
begin
  while Str[1] = ' ' do
    Delete(Str, 1,1);
  while Str[Length(str)] = ' ' do
    Delete(Str, Length(Str)-1, 1);
end;

as a function...

function Trim(Str : String):String;
begin
  Result := Str;
  while Result[1] = ' ' do
    Delete(Result, 1,1);
  while Result[Length(Result)] = ' ' do
    Delete(Result, Length(Result)-1, 1);
end;

To use them just do as follows...

var
  S : string;
begin
  S := '   Hello World   ';
  //To use the procedure do this.....
  Trim(s);
  //If you want to use the function just do this...
  S := Trim(s);
  caption := s;
end;

Cheers,
Viktor
 Hi poodle,

I am really sorry, but my answer is not correct.
As Emmdieh says, these routines are not implemernted in Delphi 1.
Unfortunatley I looked at the wrong source file.

So please reject my answer and give the points to Victor, as he has shown the right way.

Regards
  ow
Avatar of poodle

ASKER

I rejected ow, but how can I accept vitornet's answer?
ASKER CERTIFIED SOLUTION
Avatar of viktornet
viktornet
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial