Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Quickly alltrim non-alpha chars from string
Message
From
01/08/2005 16:04:33
 
 
To
01/08/2005 15:28:02
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9
Miscellaneous
Thread ID:
01037589
Message ID:
01037602
Views:
27
>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


Hi Malcolm,

Not a one liner, but try this:
nStartPos = at( left(chrtran( pcStr, '0123456789', '' ), 1), pcStr )
nEndPos = rat( right(chrtran( pcStr, '0123456789', '' ), 1), pcStr )
?substr( pcStr, nStartPos, nEndPos - nStartPos + 1 )
Regards
Herman
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform