Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Checking string for predefined format
Message
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00403485
Message ID:
00403504
Vues:
33
This message has been marked as a message which has helped to the initial question of the thread.
>Hi everyone,
>
>For APN I have this format:
>999999X-X999999X-X999999XX-XX999999X-XXXXXX,
>
> where 9 is a digit,
> X as upper case alpha,
> and - is hyphen.
>
>I have an UDF, which determines, is APN valid by inspecting each character. I'm just curious, is there more elegant and simple solution (and should be faster, of course)?
>
>Thanks in advance.


Hi Nadya,

I think the code below does what you want in the generic way.
It certainly can be improved but i'll live it to you :)
lcMask = "999999X-X999999X-X999999XX-XX999999X-XXXXXX"
lcAPN  = "123456A-B789012C-D345678EF-GH901234I-KLMNOP"

lcDigits = "0123456789"
lcLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"


lcMaskUniform = CHRTRAN( lcMask, lcDigits, REPLICATE("0", 10)) 
lcMaskUniform = CHRTRAN( lcMaskUniform, lcLetters, REPLICATE("A", 26)) 


lcAPNUniform = CHRTRAN( lcAPN, lcDigits, REPLICATE("0", 10)) 
lcAPNUniform = CHRTRAN( lcAPNUniform, lcLetters, REPLICATE("A", 26)) 


RETURN lcAPNUniform = lcMaskUniform
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform