Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Checking string for predefined format
Message
From
10/08/2000 14:04:50
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00403485
Message ID:
00403547
Views:
14
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
>
An even better solution is available in the WSH's VBScript.RegExp object, which can construct complex regular expressions and evaluate them on demand, using standard regular expression matching masks. It requires installation of WSH v 2.0; the RegExp object is documented in the WSH docs pertaining to VBScript, and is covered in detail in Wrox Press' "VBScript Programmer's Reference Manual". The masking requirement outlined above is well within the capability of the VBScript.RegExp object's pattern definition capability. I'm not going to write the code to do it, though.
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform