Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Remove excessive spaces in string
Message
De
24/07/2009 17:41:55
 
 
À
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:
01414397
Vues:
64
>>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
>
If your going to do that you should just put it in a loop
x = 'test1    test2 test3    test4  test5       test6'
DO WHILE SPACE(2) $ x
   x = STRTRAN(x, '  ', ' ')
ENDDO
Charles

"The code knows no master." - Chuck Mautz
"Everybody is ignorant, only on different subjects." - Will Rogers
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform