Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Strip leading zeros
Message
 
À
22/10/2009 12:30:02
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 8 SP1
Divers
Thread ID:
01430254
Message ID:
01430695
Vues:
70
>>>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)


Not sure if somebody already suggest this (I just saw the thread):
? CHRTRAN(LTRIM(CHRTRAN(ALLTRIM(YourField),"0"," "))," ","0")
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform