Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Quickly alltrim non-alpha chars from string
Message
De
01/08/2005 16:11:49
 
 
À
01/08/2005 15:43:29
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9
Divers
Thread ID:
01037589
Message ID:
01037605
Vues:
22
Missed that part. I think Herman's solution will get you there, but if you need a one liner, you may be able to get there by using regular expressions. Though I must admit, somethimes those can be about as clear as mud for determining what they do, at least to me.


>Hi Fred,
>
>Thanks for the suggestion, but I can't use chrtran() because of the NOTE: that follows my introduction.
>
>
>NOTE: I want to preserve embedded non-alpha chars.
>

>
>Any other ideas?
>
>Malcolm
>
>>>Any suggestions on how I can quickly alltrim all non-alpha chars from a string via either a clever VFP technique, FoxTools FLL function, or Win32 API call?
>>>
>>>My current approach below. But certainly there must be a more efficient way?
>>>
>>>NOTE: I want to preserve embedded non-alpha chars. I just want to remove leading and trailing non-alpha chars.
>>>
>>>
>>>function fulltrim( pcStr )
>>>	for lnChar = 1 to len( pcStr )
>>>		if isalpha( substr( pcStr, lnChar, 1 ) )
>>>			exit
>>>		endif
>>>	endfor
>>>	pcStr = substr( pcStr, lnChar )
>>>
>>>	for lnChar = len( pcStr ) to 1 step -1
>>>		if isalpha( substr( pcStr, lnChar, 1 ) )
>>>			exit
>>>		endif
>>>	endfor
>>>	pcStr = left( pcStr, lnChar )
>>>
>>>	return pcStr
>>>endfunc
>>>
>>>
>>>Thanks,
>>>Malcolm
>>
>>
>>z="ABC123"
>>?CHRTRAN(z,CHRTRAN(z,"ABCDEFGHIJKLMNOPQRSTUVWXYZ",""),"")
>>
>>Just add lower case if you need to include those, too.
Fred
Microsoft Visual FoxPro MVP

foxcentral.net
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform