
 |
Delphi Programmer's Resources/Examples
Triming strings:
{
This sample code is presented as is.
Although every reasonable effort has been
made to insure the soundness of the example
below, Idianna Software inc. makes no warranty
of any kind with regard to this program sample
either implicitly or explicitly.
This program example may be freely distributed for the
use of writing computer programs only. Any other use of
this material requires written permission from Idianna Software inc.
(c) 1997 Idianna Software inc. All rights reserved.
}
{
Removes leading blanks from sString
}
function LTrim(sString : String) : String;
{Author Jon Vote 10/97}
var len,s : integer;
begin
len := length(sString);
s := 1;
while (s <= len) and (sString[s] = ' ') do
s := s + 1;
if s < = len then
LTrim := Copy(sString, s, len - (s-1))
else
LTrim := '';
end; {LTrim}
{
Removes trailing blanks from sString
}
function RTrim(sString : String) : String;
{Author Jon Vote 10/97}
var len,s : integer;
begin
len := length(sString);
s := len;
while (s > 0) and (sString[s] = ' ') do
s := s - 1;
if s > 0 then
RTrim := Copy(sString, 1, s)
else
RTrim := '';
end; {RTrim}
{
Removes leading and trailing blanks from sString
}
function Trim(sString : String) : String;
{Author Jon Vote 10/97}
begin
Trim := Ltrim(Rtrim(sString));
end; {LTrim}
|