Link to home
Start Free TrialLog in
Avatar of Sling_Blade
Sling_BladeFlag for New Zealand

asked on

Replacing Space with VBCrLf in Text File

I have a large text file of words; each of the words is seperated by one empty space.

What I need to do is to replace the space that seperate the words with the new line character, vbcrlf, so that each word is on its own line.

I have create a filestream object and populated it with the contents of the file.

How can I interate through the filestream object and substitue vbcrlf for each space?

<code>
        Dim oFile As System.IO.File
        Dim oRead As System.IO.StreamReader
        oRead = oFile.OpenText("C:\WordList.txt")
</code>
ASKER CERTIFIED SOLUTION
Avatar of ericwong27
ericwong27
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Sling_Blade

ASKER

Sorry I am using vs 2003.

Here is what I have so far

  Dim oFile As System.IO.File
  Dim oRead As System.IO.StreamReader
  oRead = oFile.OpenText("C:\WordList.txt")

  Dim result As String = oRead.ReadToEnd
  result.Replace("\s+", ControlChars.CrLf)

Dim oWrite As System.IO.StreamWriter
  oRead = New StreamWriter("C:\NewWordList.txt")
  oRead.Write(strData)
  oRead.Close

However the output is exactly the same as the WordList.txt document.
Opps, I tabbed to the submit button by mistake, don't be confused by the code, here is what I meant.

  Dim oFile As System.IO.File
  Dim oRead As System.IO.StreamReader
  oRead = oFile.OpenText("C:\WordList.txt")

  Dim result As String = oRead.ReadToEnd
  result.Replace("\s+", ControlChars.CrLf)

  Dim oWrite As System.IO.StreamWriter
  oWrite = New StreamWriter("C:\NewWordList.txt")
  oWrite.Write(strData)
  oWrite.Close
Of course it works anyway!!

Thanks Heaps.