Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replace a space with nothing ??? 1

Status
Not open for further replies.

BobbaFet

Programmer
Feb 25, 2001
903
NL
hi all,

Thank you for looking at my question !!!
How can I replace
MyString := ' '; (In other words, a single space)
with
MyString := ''; (In other words nothing)

Thanx in advance, BobbaFet

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com
 
Or are you asking how to remove all the spaces from a string?
 
Yeah thats it !!!
Removing ALL the spaces from a string !!! Trim works
excellent when you want no spacing on the sides, but
it doesnt work when its in the middle of a string !!!

So basically if I trim this string:
Trim(' Cas is a good guy '); (sorry, I like myself)

The result would be this:
MyString := 'Cas is a good guy';

But I also need to get rid of ALL the spaces in between the
words ...

I do hope you guys have an answer for me, because I still
haven't figured out how to do this ...

Thanx allot,




BobbaFet

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com
 
hey guys, im sorry but I found the answer to my question!

I even made it in a function:

function RemoveSpaces(MyStr: String): String; (It returns the string)
begin
while Pos(' ',MyStr) > 0 do
Delete(MyStr, Pos(' ', MyStr), 1);
end;

It works like a charm !!! Check it out !!!

Greetz, BobbaFet

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com
 
But this replaces all occurrences of the space character and not just the leading and trailing ones. Check out strTrimCharLeft and strTrimCharRight from the JCL libraries. Peter Gore
 
That was the idea gorepj !!!

Thanx for checking out my question anyway !!! BobbaFet

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com
 
Why usin loops when there is simplier way to do it?
Try this:

Result := StringReplace(s, ' ', '', [rfReplaceAll]);
 
A simple solution is use the StringReplace function.

MyString := 'I want remove the spaces in string :))';

MyNewString := StringReplace(MyString, #32, '', [rfReplaceAll, rfIgnoreCase]);

Enjoy
 
Hey guys thanx for your responses, but I already got it working, so I'm not going to use your solutions, although I'm sure they work just as well.

Greetz, BobbaFet

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top