Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to compress space in string?
Message
 
À
23/05/2003 04:55:15
Lutz Scheffler
Lutz Scheffler Software Ingenieurbüro
Dresden, Allemagne
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00792083
Message ID:
00792121
Vues:
16
Agnes,

If you search for something without loop, you could try the

"Reduce" function from FoxTools.fll

SET LIBRARY TO FoxTools.fll
lcString = "one 123 333"
lcNewString = Reduce(lcString)
? lcNewString
one 123 333


Cheers,

Zoran





>Hi Greg,
>no it does'nt. ::(.
>
>Try a = '12......34...56...'
>Return is 12..34.56. not 12.34.56. as expected.
>
>I know I can do something like
>
>a = '12......34...56...6..5.'
>DO WHILE !EMPTY(OCCURS('..',a))
> a=STRTRAN(a,'..','.')
>ENDDO &&!EMPTY(OCCURS('..',a))
>?a
>
>but I search for something without loop.
>
>Agnes
>
>>Agnes,
>>
>>Does this work ? Replace the dots with spaces
>>
>>
>>
>>a = '12...34...56...'
>>? StringSearchAndReplace(a, '..', '.')
>>
>>*-------------------------------------------------------------------------------
>>function StringSearchAndReplace(Searched, SearchFor, ReplaceWith, IgnoreCase)
>>
>>	local i, Offset, SearchForLength, ReplaceWithLength
>>	
>>	SearchForLength = len(SearchFor)
>>	ReplaceWithLength = len(ReplaceWith)
>>	Offset = 1
>>	
>>	do case
>>	case IgnoreCase
>>		i = atc(SearchFor, substr(Searched, Offset))
>>		do while !empty(i)
>>			i = i + Offset - 1
>>			Searched = stuff(Searched, i, SearchForLength, ReplaceWith)
>>			Offset = Offset + ReplaceWithLength
>>			i = atc(SearchFor, substr(Searched, Offset))
>>		enddo
>>	otherwise
>>		i = at(SearchFor, substr(Searched, Offset))
>>		do while !empty(i)
>>			i = i + Offset - 1
>>			Searched = stuff(Searched, i, SearchForLength, ReplaceWith)
>>			Offset = Offset + ReplaceWithLength
>>			i = at(SearchFor, substr(Searched, Offset))
>>		enddo
>>	endcase
>>	
>>	return Searched
>>endfunc
>>*--------------------------------------------------------------------------
>>
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform