Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Strip leading zeros
Message
From
20/10/2009 19:32:27
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
 
 
To
20/10/2009 19:25:21
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 8 SP1
Miscellaneous
Thread ID:
01430254
Message ID:
01430270
Views:
54
>>In the present case, wouldn't it be simpler to do a padl(...) on whatever the user types, before doing the comparison?
>
>I dont' think so. There's no way to determine how many zero's to pad with. BOTH the following values should yield TRUE
>0024567890
>0000000290
>
>I'm reasonably sure what the user types needs to stay as-is on the right side of the = statement and we need some expression on the left to strip off the leading blanks (as Naomi said - easy in VFP 9).
>
>If anyone can come up with something better, I'm all ears (........well..........eyes)
>but not to waste too much brain-power because I do have a working solution.

A simple pedestrian, old-style loop, perhaps:
do while inlist(left(lcStr, 1), " ", "0")
   lcstr=substr(lcstr,2)
enddo
And padl() it with spaces to whichever length you want then.

update: ah, now I see what you mean... you need to build a search list. You can create an array of "2", "02", "002", "0002" etc until the length of the string is 10, and then scan for anything that is in the array.
lcStr="{what user entered}"
dime aStr[10-len(lcStr)+1]
for i=0 to alen(astr)-1
  astr[i+1]=repl("0", i)+lcstr
endfor
scan for ascan(astr, yourfield)>0
...
endscan
Alternately, you could build a list for the inlist function, and then macro it... something like
lcExpr=[inlist(myfield, "290", "0290", "00290","000290", "0000290", .... "0000000290")]
* and then 
scan for &lcExpr
...
endscan
Actually, you could build these lists backwards, making sure that you padl() whatever the user enters with zeros to fill c(10), then build the array or list by chopping one character from the left until the first character is a nonzero.

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform