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
Author: Michael Madigan
Posted: 2005-08-01 14:48:27 Link
I can't think of anything better than that. However,
? fulltrim(",@#$a&&bc$%^") causes an error
--- Malcolm Greene <profox@bdurham.com> wrote:
> 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
>
>
> _______________________________________________
> Post Messages to: ProFox@leafe.com
> Subscription Maintenance:
> http://leafe.com/mailman/listinfo/profox
> OT-free version of this list:
> http://leafe.com/mailman/listinfo/profoxtech
> ** All postings, unless explicitly stated otherwise,
> are the opinions of the author, and do not
> constitute legal or medical advice. This statement
> is added to the messages for those lawyers who are
> too stupid to see the obvious.
>
Author: Jean Laeremans
Posted: 2005-08-01 14:56:30 Link
On 8/1/05, Malcolm Greene <profox@bdurham.com> wrote:
> 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?
>
Something like
CHRTRAN(cvar,CHRTRAN(cvar,'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',""),"")
A+
jml
Author: Malcolm Greene
Posted: 2005-08-01 15:01:28 Link
Michael,
> fulltrim(",@#$a&&bc$%^") causes an error
That's because VFP treats the && as comment char and truncates the
function at that point.
BTW: Sorry to hear the bad news about your job. I'm hoping for the best
for you. Now get cracking on your own software products before that
paycheck dries up!
Malcolm
On Monday 01 August 2005 15:30, Malcolm Greene wrote:
> 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?
FUNCTION JustAlpha(txt)
goodChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + ;
goodChars = goodChars + LOWER(goodChars)
badChars = CHRTRAN(txt, goodChars, "")
RETURN CHRTRAN(txt, badChars, "")
--
-- Ed Leafe
Author: Malcolm Greene
Posted: 2005-08-01 15:03:11 Link
Jean,
Thanks for the chrtran() idea but I need to preserve embedded non-alpha
chars. In other words I want to remove leading and trailing non-alphas
but keep any non-alphas that are in the middle of the string.
Any other ideas?
Malcolm
Author: Malcolm Greene
Posted: 2005-08-01 15:05:05 Link
Hi Ed,
Thanks for the code but I need to alltrim leading/trailing non-alpha
chars BUT keep any embedded non-alphas in place.
Any other ideas?
Malcolm
Author: Michael Madigan
Posted: 2005-08-01 15:08:59 Link
Maybe I can market fulltrim() :)
--- Malcolm Greene <profox@bdurham.com> wrote:
> Michael,
>
> > fulltrim(",@#$a&&bc$%^") causes an error
>
> That's because VFP treats the && as comment char and
> truncates the
> function at that point.
>
> BTW: Sorry to hear the bad news about your job. I'm
> hoping for the best
> for you. Now get cracking on your own software
> products before that
> paycheck dries up!
>
> Malcolm
>
>
> _______________________________________________
> Post Messages to: ProFox@leafe.com
> Subscription Maintenance:
> http://leafe.com/mailman/listinfo/profox
> OT-free version of this list:
> http://leafe.com/mailman/listinfo/profoxtech
> ** All postings, unless explicitly stated otherwise,
> are the opinions of the author, and do not
> constitute legal or medical advice. This statement
> is added to the messages for those lawyers who are
> too stupid to see the obvious.
>
Author: Johnson, Fletcher S (N-Superior Technical Resources Inc.)
Posted: 2005-08-01 15:10:18 Link
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]
Author: Malcolm Greene
Posted: 2005-08-01 15:14:20 Link
> Maybe I can market fulltrim() :)
I drank a lot of Ultratrim ? diet drinks a few years back. If your
fulltrim(tm) tastes better than horse crap then you have a big advantage
over all the other diet drinks I've "enjoyed" ;)
Malcolm