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 sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Removing all spaces in a text

Status
Not open for further replies.

RemingtonSteel

Programmer
Jul 14, 2006
65
GB
Hello to everyone!
Is there any function in foxpro that removes all spaces (leading,trailing and even in between) on a text.

For example

Problem = ' Maria de la fuente '
Answer = 'Mariadelafuente'

Thanks in advanced!
Gene
 
This should work for you.

gcString = ' Maria de la fuente '
? STRTRAN(gcString, ' ', '')

If you can't stand behind your troops, stand in front of them.
Semper Fidelis

Jim
 
Mike,

My first thought was -- like yours -- to suggest REDUCE(). But it doesn't quite do what Gene requires. It compacts multiple internal spaces to a single space, rather than eliminate them completely.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
[ ]
More info about removing spaces here: thread184-1262115

mmerlinn


"We've found by experience that people who are careless and sloppy writers are usually also careless and sloppy at thinking and coding. Answering questions for careless and sloppy thinkers is not rewarding." - Eric Steven Raymond
 
Reduce() is good to keep a single space in between words, just remove unneeded further spaces and whitespace.

Reduce also replaces tabs with a single space. It's main purpose surely is for texts to remove unwanted additional whitespace, but keep a single space for each series of consequtive whitespace.

Gene simply needs a ChrTran(text," ",""). In cases where you process many many texts, ChrTran() itself is 3 times as fast as StrTran() for this kind of single char replacements. And if you want to remove tabs too, do ChrTran(text," "+chr(9),"").

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top