Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Remove empty and non-alpha chars in string?
Message
From
11/01/2003 08:25:16
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
11/01/2003 08:08:53
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00740604
Message ID:
00740617
Views:
21
>Thank you Cetin. Although a little more complicated solution than Hilmar's, it will be worth to check it out.
>Thank you for your time.
>
>Ulises

Oh just checked it. Not more complicated. Added nonalpha char removal :)
For only space corresponding code is :

lcReduced = CHRTRAN(lcStr,' ','')
lcAlphaSet=""
for ix=asc('A') to asc('Z')
 lcAlphaSet=lcAlphaSet+chr(ix)
endfor
lcAlphaSet = lcAlphaSet+lower(lcAlphaSet)
Above part creates a string of alpha chars (assuming US alphabet only). Result string is something like "ABCD...Zabcd...z".

lcReduced = CHRTRAN(lcStr,chrtran(lcStr,lcAlphaSet,''),'')

Inner chrtran(lcStr,lcAlphaSet,'') removes all alpha chars from string, leaving out nonalpha ones (including space).
Applying inner chrtran's result string to chrtran(lcStr, NonAlphaOnly, '') gives only alpha chars in string.

Maybe it's easier to understand with getting only digits from a string (ie: You want to get 821 from "LAP8-21") :

lcStr = "LAP8-21"
lcDigits = "0123456789" && This is like AlphaSet - Digitset
lcInnerChrtran = chrtran(lcStr, lcDigits, '') && "LAP-"
*chrtran(lcStr, "LAP-", '') && Remove "LAP-" chars from lcStr
lcOuterChrTran = chrtran(lcStr, lcInnerChrTran, '')

If you knew what nonalpha charset would be it is shorter :
MyNonAlphaChars = " '!@#..."+["]
*Replace all chars of lcStr with 'nothing' if it's in MyNonAlphaChars
lcReduced = chrtran(lcStr,MyNonAlphaChars,'')
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform