Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Strip leading zeros
Message
From
22/10/2009 12:30:02
 
 
To
21/10/2009 09:02:05
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 8 SP1
Miscellaneous
Thread ID:
01430254
Message ID:
01430693
Views:
590
>>I need an expression that essentially strips away the leading zeros and allows a comparison to another value. So if the user enters "2" we would filter by/select all records where the first non-zero character would be "2", getting (with EXACT OFF)......
>>
>>"0002567890"
>>"0000027890"
>>"00002678-1"
>>"0000000002"
>>etc.
>
>Two options: either remove the zeros from the field values on the records (most time consuming) or add the zero's to the user's input (least time consuming). In VFP 9 you can use the LTRIM function to remove leading zero's. But I don't think that option was available in VFP 8. Given that I would recommend adding the zeros to the user expression:
>
>
>lcUserEnteredText = "989"     && Entered from a form input or something...
>
>SELECT mytable
>LOCATE FOR myfield = PADL(lcUserEnteredText,10,"0")
>IF FOUND()
>ELSE
>ENDIF
>
Thanks for taking the time to respond.

I probably didn't express this clearly enough in my original post, but I need an expression that can be used as part of a SELECT WHERE or SET FILTER TO command that would result in ALL the above values being TRUE.

Padding the user input with zeros doesn't work because each record needs a different number of zeros. So I need a way to remove the leading zeros (a VFP 8 equivalent to the VFP 9 LTRIM function)
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform