Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Remove excessive spaces in string
Message
De
24/07/2009 17:13:58
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP2
Network:
Windows 2008 Server
Database:
Visual FoxPro
Application:
Desktop
Divers
Thread ID:
01414370
Message ID:
01414385
Vues:
73
>I have a string that contains many spaces. For example
>
>
x = 'test1    test2 test3    test4  test5       test6'
>
>how can I format the string to contain only one space between the 'test' values. For example how do get it to do the following:
>
>
x = 'test1 test2 test3 test4 test5 test6'
>
>I thought about using strtran() command but I don't it works the way I want it too.

Naomi's answer is simple and elegant.

You can do the same thing with successive or nested STRTRAN() calls e.g.
x = 'test1    test2 test3    test4  test5       test6'

x = STRTRAN( x, SPACE( 8 ), SPACE( 1 ) )
x = STRTRAN( x, SPACE( 8 ), SPACE( 1 ) )
x = STRTRAN( x, SPACE( 4 ), SPACE( 1 ) )
x = STRTRAN( x, SPACE( 4 ), SPACE( 1 ) )
x = STRTRAN( x, SPACE( 2 ), SPACE( 1 ) )
x = STRTRAN( x, SPACE( 2 ), SPACE( 1 ) )

?x
* Above handles up to 64 spaces ( 8 x 8 )
* Adding 2 more lines at the top with SPACE( 16 ) would increase capacity to 256 spaces ( 16 x 16 )
* etc.

* I suspect the FoxTools REDUCE() function may be a recursive implementation of the above
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform