Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Removing / from dates and - from sorts...
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00488037
Message ID:
00489384
Vues:
19
>>Any ideas brethren?
>>
>>I am appending a CSV file into a table in a dbc. The CSV file contains dates in the format 2001/03/23 and sort codes in the format 56-12-09. Is there anything I can do at table or dbc level to remove the /s and the -s as each field is appended?
>>
>>What I am after is 20010323 for the date and 561209 for the sort code...
>
>Got access to the Windows Script Host? If so consider:
oRE = CREATEOBJECT("VBScript.RegExp")
>* lcfile is the CSV file
>lcstring = FILETOSTR(lcfile)
>* Remove the /
>oRE.Pattern = "(\d+)\/(\d+)\/(\d+)"
>oRE.Global = .T.
>lcstring = oRE.Replace(lcstring, "$1$2$3")
>oRE.Pattern = "(\d+)\-(\d+)\-(\d+)"
>lcstring = oRE.Replace(lcstring, "$1$2$3")
and save the string back using STRTOFILE().
>
>Now admittedly, CHRTRAN() could do the same thing, but if there are any slashes or hyphens that need to be retained, they would be changed too. With this, they won't be.

I'd be a bit more restrictive about the substitutions, using the exact lengths to ensure that something that accidentally matched with the wrong template didn't get involved, and require the presense of a word boundary, so embedded strings aren't touched:
lcstring = FILETOSTR(lcfile)
* try lcstring = '2001/02/29,01/02/09,01-02-09,001-1-09,A01-02-09,01-02-09'
* as some test examples
* Remove the /, within word boundaries if it's really a CSV
oRE.Pattern = "\b(\d{4})/(\d{2})/(\d{2})\b"  && / is not escaped
oRE.Global = .T.
lcstring = oRE.Replace(lcstring, "$1$2$3")
* Remove the -, within word boundaries if it's really a CSV
oRE.Pattern = "\b(\d{2})\-(\d{2})\-(\d{2})\b"
lcstring = oRE.Replace(lcstring, "$1$2$3")
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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform