Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Removing spaces in text file using FSO

Status
Not open for further replies.

cmcgann

Programmer
May 31, 2000
22
0
0
IE
Hi all,<br><br>I am trying to remove spaces in a text file, using FSO<br><br>Does anyone know how i can do this.<br><br>The following is the logic that i need to use<br><br><br><br>Sub StripSpaces()<br><br>Dim fs As FileSystemObject<br>Dim ans As String<br><br><br>Set fs = CreateObject(&quot;Scripting.filesystemobject&quot;)<br>Set a = fs.OpenTextFile(&quot;c:\a16.txt&quot;)<br><br>Do Until a.AtEndOfStream = True<br><br>&nbsp;&nbsp;result = a.Readline<br>&nbsp;&nbsp;If result = &quot; &quot; Then<br>&nbsp;&nbsp;???? remove (result)<br>&nbsp;&nbsp;End If<br>&nbsp;&nbsp;<br>Loop<br>a.Close<br><br><br>'''save file<br><br><br>thanks <br><br>Conor
 
I would try loading all the lines into a collection, then go through the collection and remove all the spaces, then write the collection into the file. <p>Karl<br><a href=mailto:kb244@kb244.8m.com>kb244@kb244.8m.com</a><br><a href= </a><br>Experienced in , or have messed with : VC++, Borland C++ Builder, VJ++6(starting),VB-Dos, VB1 thru VB6, Delphi 3 pro, Borland C++ 3(DOS), Borland C++ 4.5, HTML,Visual InterDev 6, ASP(WebProgramming), QBasic(least i didnt start with COBOL)
 
A possability is to use the vb Function Split.&nbsp;&nbsp;It will place each &quot;delimited&quot; item in an array.&nbsp;&nbsp;Using the (Default) delimiter (&quot; &quot;) you end up with a list of the tokens (e.g. 'words') in an array.&nbsp;&nbsp;Concatenating each element of the array would return the original &quot;line&quot; with all spaces removed.<br><br>E.G.:<br><br><br>Sub StripBlanks<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Dim MyWds() as String&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Storage for TokensWords<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Dim Idx as Integer<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Dim MyLine as String<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MyWds = Split(LineIn, &quot; &quot;)&nbsp;&nbsp;&nbsp;'Get Tokes/Words in Array<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;For Idx = 0 to UBound(MyWds)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MyLine = MyLine & MyWds(Idx)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Next Idx<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;StripBlanks = MyLine<br><br>End Sub
 
or if you wanted you can throw all the lines into one big string(or a array of lines) and use the replace(thestring, &quot; &quot;, &quot;&quot;) command. <p>Karl<br><a href=mailto:kb244@kb244.8m.com>kb244@kb244.8m.com</a><br><a href= </a><br>Experienced in , or have messed with : VC++, Borland C++ Builder, VJ++6(starting),VB-Dos, VB1 thru VB6, Delphi 3 pro, Borland C++ 3(DOS), Borland C++ 4.5, HTML,Visual InterDev 6, ASP(WebProgramming), QBasic(least i didnt start with COBOL)
 
... just adding to my previous response.<br><br>You can also use the vbFunction
 
Oops,&nbsp;&nbsp;Something appears to have been lost (in the Translation?)<br><br>To Continue,<br><br>You can also use the vbFunction
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top