Hi,
I have a file which is a list of French first-names in four CSV-type
columns
Agnès-Céline;Agnès Céline;AGNES-CELINE;AGNES CELINE
Pat;Pat;PAT;PAT
etc
The first column is correctly spelt.
But 2nd 3rd and 4th columns are mis-spellings.
2=No hyphen. 3=Block capitals. 4=Block capitals and no hyphen.
The idea is to use this first-names file to correct another file of names
and adresses where first-names may be mis-spelt..
The idea is to scan through the adresses file line by line checking for the
prescence of strings identical to data in columns 2, 3 or 4.
Any such data should then be replaced by the data from column 1.
This works BUT !! ...
Incidences of PATTON (as in PATTON STREET) were getting replaced by PatTON.
etc.
BANNER became BAnneR, (i.e. the ANNE rplaced by Anne.)
So I decided to check for whole words, thinking that as my data in the
adress file is tab-separated I could look for
chr(9)&ANNE&chr(9) and replace that with chr(9)&Anne&chr(9)
But that doesn't work and I can't figure out why.
Is it Unicode/Ascii ?
Is there no way to use Replace() on only whole words ?
It's driving me nuts.
Almost there but not quite!
Here's the script.
TIA
Scottie.
---------------------
'Create a File System Object
on error resume next
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
'Get the file contents
Dim MyPrenoms
Set MyPrenoms = fso.OpenTextFile( "C:\VBS STUFF\prénoms.csv",ForReading,
False)
'Loop through counting the lines
LineCount=0
Dim MyArray (4000, 4)
Do While Not MyPrenoms.AtEndOfStream
MyLine = MyPrenoms.readLine
'msgbox Myline
LineCcontents = Split(MyLine, ",", -1, 1)
'MSGBOX LineCcontents(0) & LineCcontents(1) & LineCcontents(2)&
LineCcontents(3)
MyArray(LineCount,0) = LineCcontents(0)
MyArray(LineCount,1) = LineCcontents(1)
MyArray(LineCount,2) = LineCcontents(2)
MyArray(LineCount,3) = LineCcontents(3)
' msgBox MyArray(LineCount,0) & MyArray(LineCount,1) &
MyArray(LineCount,2) & MyArray(LineCount,3)
LineCount = LineCount + 1
Loop
msgbox "LineCount Prénoms : " & LineCount
Dim MyFileAdressesIn
Set MyFileAdressesIn = fso.OpenTextFile("C:\VBS STUFF\lapat1.txt",
1, False)
Set MyFile = fso.GetFile("C:\VBS STUFF\lapatOut.txt")
MyFile.Delete
Dim MyFileAdressesOut
Set MyFileAdressesOut = fso.OpenTextFile ("C:\VBS
STUFF\lapatOut.txt", ForAppending, True)
do while RL < 20 '---------for testing
MyAdresse = MyFileAdressesIn.readLine
RL = RL + 1
MyOldAdresse = MyAdresse
For i = 0 to Linecount
For j = 1 TO 3
' If Instr(1,Myadresse, chr(9) &trim( MyArray(i,j) )&
chr(9), 0 ) then
' MsgBox "Found" & vbcrlf & MyAdresse & vbcrlf &
MyArray(i,j)
' End if
MyAdresse = Replace( MyAdresse, _
chr(9) & MyArray(i,j) & chr(9), _
chr(9) & MyArray(i,0) & chr(9), 0 )
MsgBox MyOldAdresse & vbcrlf & _
MyAdresse & vbcrlf & _
chr(9)& MyArray(i,j)& chr(9)& vbcrlf & _
chr(9)& MyArray(i,0)& chr(9)
Next 'i
Next 'j
MyFileAdressesOut.writeline(MyAdresse)
Loop
'Cleanup
MyMyPrenoms.Close
MyFileAdressesIn.Close
MyFileAdressesOut.Close
Set MyFileContents = Nothing
Set fso = Nothing
msgbox "Finished" & "LineCount " & LineCount & vbcrlf & _
" i " & i & vbcrlf & _
" j " & j