Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


RE: Search & Replace - Finding 1st Position

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,37664
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> RE: Search & Replace - Finding 1st Position
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: <<   < prev  1 [2]
Login
Message << Older Topic   Newer Topic >>
 RE: Search & Replace - Finding 1st Position - 9/13/2006 2:44:29 AM   
  ebgreen


Posts: 4970
Score: 31
Joined: 7/12/2005
Status: offline
For the lines that you posted as examples above, they all have the proper number of *s. You can run this code to verify that:


      

_____________________________

"... 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

(in reply to ignignokt)
 
 
Post #: 21
 
 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

(in reply to ebgreen)
 
 
Post #: 22
 
 
Page:  <<   < prev  1 [2]
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> RE: Search & Replace - Finding 1st Position Page: <<   < prev  1 [2]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts