Delete multiple spaces in a string?

pettalpettal Member Posts: 20
Hi,

Been twisting my head tring to delete multiple spaces in a string and can't figuire it out..

Tried:
DELCHR(String, '=', ' ');

Which I thought would work... tried searching on STRPOS and then getting the multiple spaces out... nah that didn't work as it just finds the first instance.

Any ideas or help appreciated!

Thanks

P

Comments

  • pettalpettal Member Posts: 20
    That DELCHR has multiple spaces in before I posted so just imagine that it had 10 spaces in! :P
  • matttraxmatttrax Member Posts: 2,309
    Yeah, it's a pain to do this one. Maybe there's a better way, but this is how I do it:
    WHILE ( STRPOS(String, 'aa') > 0 ) DO BEGIN
       String := DELSTR(String, STRPOS(String, 'aa'), 1);  
    END;
    

    Pretend the 'aa' is multiple spaces. And I typed that from memory, so it might be a little off. I found that I couldn't do a DELCHR because it would delete all the spaces, and I still wanted to leave one. Searching for two consecutive spaces and using the DELSTR function to delete one of them.
  • pettalpettal Member Posts: 20
    Nice one Mattrax!

    That works a treat! =D>
Sign In or Register to comment.