Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Strip leading zeros
Message
 
À
22/10/2009 15:55:08
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:
01430819
Vues:
71
Rich,

You can set ANSI OFF and the first one will work as you want, problem is that the second one will match an extra record as '2' = '26'. One thing you can do is to change the pattern in the regular expression, for example:
clear
LOCAL laTest(4), i

CREATE CURSOR c_test (ID C(10))

laTest[1]	= "0002567890"
laTest[2]	= "0000027890"
laTest[3]	= "00002678-1"
laTest[4]	= "0000000002"

FOR i = 1 TO ALEN(laTest, 1)
	INSERT INTO c_test values (laTest[i])
NEXT i

loRegEx			= Createobject('VBScript.RegExp')

loRegEx.Pattern		=  '^0+2(.*)'
SELECT c_test.ID FROM c_test WHERE loRegEx.Test(c_test.ID)
&& only record 4 returned and should have been all 4 records

loRegEx.Pattern		= '^0+26(.*)'
SELECT c_test.ID FROM c_test WHERE loRegEx.Test(c_test.ID)
&& nothing returned. and should have been record 3
Of course you can make the regular expression as complex as you want, lets say you want the ones that start with to 2 and end with 890, you simply do
loRegEx.Pattern		= '^0+2(.*)(890)$'
SELECT c_test.ID FROM c_test WHERE loRegEx.Test(c_test.ID)
(well, not very complex, just to give you an idea)

>Thanks again. I think either I didn't explain what I need properly or this won't work. Using the same c_test cursor I tried
>SELECT c_test.ID FROM c_test WHERE loRegEx.Replace(c_test.ID, '$1') = '2' 
>&& only record 4 returned and should have been all 4 records
>
>SELECT c_test.ID FROM c_test WHERE loRegEx.Replace(c_test.ID, '$1') = '26'  
>&& nothing returned. and should have been record 3
>
"The five senses obstruct or deform the apprehension of reality."
Jorge L. Borges?

"Premature optimization is the root of all evil in programming."
Donald Knuth, repeating C. A. R. Hoare

"To die for a religion is easier than to live it absolutely"
Jorge L. Borges
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform