Login | |
|
 |
RE: Search & Replace - Finding 1st Position - 9/13/2006 4:49:51 AM
|
|
 |
|
| |
ignignokt
Posts: 31
Score: 0
Joined: 9/12/2006
Status: offline
|
I got it to work. I just have to read the file twice and then run the function. dim o dim p dim q dim r dim fs dim strStarter dim strCleaned dim strOriginal dim nFields Const ForReading = 1 Const ForWriting = 2 set fs = CreateObject("Scripting.FileSystemObject") set o = fs.OpenTextFile("C:\temp\t2.txt", ForReading, False) set p = fs.CreateTextFile("C:\temp\t3.txt", True) Do While o.AtEndOfStream <> True strStarter = o.ReadLine strStarter = Replace(strStarter, " ", "") strStarter = Replace(strStarter, vbNewLine, "") strStarter = Replace(strStarter, vbCr, "") strStarter = Replace(strStarter, vbTab, "") strStarter = Replace(strStarter, vbLf, "") strStarter = Replace(strStarter, vbCrLf, "") strStarter = Replace(strStarter, vbFormFeed, "") strStarter = Replace(strStarter, vbNullChar, "") strStarter = Replace(strStarter, vbNullString, "") strStarter = Replace(strStarter, "TEST", vbNewLine & "TEST") p.Write(strStarter) Loop o.Close p.Close set q = fs.OpenTextFile("C:\temp\t3.txt", ForReading, False) set r = fs.CreateTextFile("C:\temp\t4.txt", True) Do While q.AtEndOfStream <> True strStarter = q.ReadLine strCleaned = TrimExtraDelimiters(strStarter, 29) r.WriteLine(strCleaned) Loop Function TrimExtraDelimiters(strOriginal, nFields) dim arrParts dim strConCat dim i arrParts = Split(strOriginal, "*") If UBound(arrParts) < nFields Then TrimExtraDelimiters = strOriginal Exit Function End If For i = nFields to UBound(arrParts) strConCat = strConCat & arrParts(i) Next ReDim Preserve arrParts(nFields) arrParts(UBound(arrParts)) = strConCat TrimExtraDelimiters = Join(arrParts, "*") End Function
|
|
| |
|
|
|
| |
|
|
 |
|
 |
|
|