Jump to content

Is there a function to delete spaces from a string?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
standard

standard

    Newbie

  • Members
  • Pip
  • 4 posts
Hello. Just a quickie

Is there a function that removes all spaces from a given string.

So say i have the words (''Hello To All'')
Can i use a function so that the string becomes (''HelloToAll'')

Any help would be appreciated. Thanks in advance

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Delphi Basics : StringReplace command
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
2710

2710

    Programmer

  • Members
  • PipPipPipPip
  • 110 posts
nice one adam :)

#4
Pr0grammer

Pr0grammer

    Newbie

  • Members
  • Pip
  • 3 posts

Quote

So say i have the words (''Hello To All'')
Can i use a function so that the string becomes (''HelloToAll'')

function MyTrim(txt : String) : String;
var
 tmp : String;
 n : Integer;
begin
 tmp :='';
 for n:=1 to StrLen(PChar(txt)) do
  begin
   if RightStr(LeftStr(txt,n),1) <> ' ' then
     tmp := tmp +  RightStr(LeftStr(txt,n),1);
  end;
 Result := tmp;
end;

For Use :
procedure TForm1.Button1Click(Sender: TObject);
begin
 Edit1.Text := MyTrim(Edit1.Text);
end;

Good Luck