Author: Johnson, Fletcher S (N-Superior Technical Resources Inc.)
Posted: 2005-08-01 at 15:10:18
Malcolm,
If there is a valid number in the mix, ie:
Sfafalea69.6785aervcaer
And all you want is 69.678, then you only need to remove the leading
characters.
Val("69.678adfkjhajkdhf") will return 69.678
No need to remove trailing chars. On the other hand, if you need the
numbers but they are not "valid" numbers, then it's a little trickier.
Also, I would think that your code would need some "Not" statements in
front of the IsAlpha() functions. Or you may want to change those to
IsDigit(). Otherwise, it appears you will exit the loop on the first
characater you find.
The following might do what you want for values that are not true
numbers:
lParamater tcVar
Local lnctr, lcVal
lcVal = ""
For lnCtr = 1 to len( tcVar)
if substr( tcVar, lnCtr) $ "0123456.-+"
lcVal = lcVal + substr( tcVar, lnCtr)
endif
Next
Return lcVal
-----Original Message-----
From: profoxtech-bounces@leafe.com [mailto:profoxtech-bounces@leafe.com]
On Behalf Of Malcolm Greene
Sent: Monday, August 01, 2005 12:30 PM
To: profoxtech@leafe.com
Subject: Quickly alltrim non-alpha chars from string
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.
<code>
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
</code>
Thanks,
Malcolm
[excessive quoting removed by server]