Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Strip leading zeros
Message
 
À
22/10/2009 12:24:27
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:
01430714
Vues:
51
>Thanks for showing me this. I've never worked with regular expressions. Is there any way to incorporate it into a SELECT WHERE or SET FILTER TO statement?

Sure you can use it, speed might be an issue thou.
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')

with loRegEx as VBScript.RegExp
	.Pattern		= '^0+(.*)'
	.IgnoreCase		= .T.
	.Global			= .T.
ENDWITH

SELECT CAST(loRegEx.Replace(c_test.ID, '$1') as C(10)) as ID FROM c_test ORDER BY 1

SELECT c_test

BROWSE FOR loRegEx.Replace(c_test.ID, '$1') = '27890'

SET ANSI on
SELECT c_test.ID FROM c_test WHERE loRegEx.Replace(c_test.ID, '$1') = '27890'
"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
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform