Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Checking string for predefined format
Message
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00403485
Message ID:
00403529
Views:
27
This message has been marked as the solution 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
>>
>
>Great!!!!! And elegant :)


One more try :)
lcMask = "999999X-X999999X-X999999XX-XX999999X-XXXXXX"
lcAPN  = "123456A-B789012C-D345678EF-GH901234I-KLMNO"

lcDigits = "0123456789"
lcLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

lcAPNUniform = CHRTRAN( lcAPN, lcDigits+lcLetters, ;
                     REPLICATE("9", 10)+ REPLICATE("X", 26)) 

RETURN lcAPNUniform = lcMask
--sb--
Previous
Reply
Map
View

Click here to load this message in the networking platform