Login | |
|
 |
RE: Search & Replace - Finding 1st Position - 9/12/2006 6:17:19 AM
|
|
 |
|
| |
ebgreen
Posts: 5246
Score: 31
Joined: 7/12/2005
Status: offline
|
Oooh...this will be a tricky one. I'll try to come up with a good way and in the meantime someone like ehvbs will come along with a better solution than I'll come up with and he'll have a two page summary on how it works. In the meantime though, I'd like to make sure that I have the situation correct. You have a string (well several of them one on each line but we'll just look at one). This string will have at least 29 * characters in it. Any * characters after the 29th one need to be removed. Is this correct?
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: Search & Replace - Finding 1st Position - 9/12/2006 6:35:40 AM
|
|
 |
|
| |
ebgreen
Posts: 5246
Score: 31
Joined: 7/12/2005
Status: offline
|
Will there be any other data mixed in there with the 30th+ *s or would it be safe to simply delete everything from the 30th * on (including the 30th * itself)?
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: Search & Replace - Finding 1st Position - 9/12/2006 6:46:02 AM
|
|
 |
|
| |
ebgreen
Posts: 5246
Score: 31
Joined: 7/12/2005
Status: offline
|
If this is true: quote:
Each line is a row from a database. Each field in that row seperated by a *. There should only be 30 fields or 29 *'s in one line. Then how is there data after the 30th *? Wouldn't that imply more than 30 fields in the DB record?
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: Search & Replace - Finding 1st Position - 9/12/2006 7:05:39 AM
|
|
 |
|
| |
ebgreen
Posts: 5246
Score: 31
Joined: 7/12/2005
Status: offline
|
Ok,see if this will work. You will want to call it with each line that you want to clean up and it will return the cleaned up line. If the variable holding the line is called strLine, then you would do this: strCleaned = TrimExtraDelimiters(strLine, 30) 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
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: Search & Replace - Finding 1st Position - 9/12/2006 10:36:21 PM
|
|
 |
|
| |
ignignokt
Posts: 31
Score: 0
Joined: 9/12/2006
Status: offline
|
Thanks for your help. Im getting a Type Mismatch error where I have the line: strCleaned = Trim(strStarter, 30). Below is my code: dim o dim p 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, vbCr, "") strStarter = Replace(strStarter, vbCr, "") strStarter = Replace(strStarter, vbTab, "") strStarter = Replace(strStarter, vbLf, "") strStarter = Replace(strStarter, vbCrLf, "") strStarter = Replace(strStarter, vbNewLine, "") strStarter = Replace(strStarter, vbCrNullChar, "") strStarter = Replace(strStarter, "TEST", vbNewLine & "TEST") strCleaned = Trim(strStarter, 30) p.Write(strCleaned) Loop o.Close p.Close Sub Trim (strOriginal, nFields) dim arrParts dim strConCat dim i arrParts = Split(strOriginal, "*") If UBound(arrParts) < nFields THen Trim = strOriginal Exit Sub End If For i = nFields to UBound(arrParts) strConCat = strConCat&arrParts(i) Next ReDim Preserve arrParts(nFields) arrParts(UBound(arrParts)) = strConCat Trim = Join(arrParts, "*") End Sub
|
|
| |
|
|
|
|