Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to compress space in string?
Message
De
23/05/2003 04:39:58
 
 
À
23/05/2003 04:29: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:
00792094
Vues:
25
>>>Hi
>>>
>>>I have a string like
>>>
>>>"IOBJ_IX I,PROJE_T_IX I,PARENT_IX I,ITYP I,ISUBTYP I"
>>>
>>>and would like to transform it to
>>>
>>>"IOBJ_IX I,PROJE_T_IX I,PARENT_IX I,ITYP I,ISUBTYP I".
>>>
>>>IOW I like to reduce multiple occurences of Space to one Char.
>>>
>>>What is the best command to use?
>>>
>>>TIA
>>
>>Agnes
>>
>>
>>cStr = "ABC  XYZ  123"
>>? StrTran(cStr, "  ", " " ) && Replace double spaces with single spaces
>>
>
>Hi Jos,
>

>Yes, thats correct. But this works for double only. If they are tripple or higher it fails.
>ok.
>
>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
*--------------------------------------------------------------------------
Gregory
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform