• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 927
  • Last Modified:

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>
0
Sling_Blade
Asked:
Sling_Blade
  • 3
1 Solution
 
ericwong27Commented:


If you are using VS 2005

Imports System.Text.RegularExpressions

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim fileContents As String
        fileContents = My.Computer.FileSystem.ReadAllText("C:\Test.txt")
        fileContents = Regex.Replace(fileContents, "\s+", ControlChars.CrLf)

    End Sub


End Class
0
 
Sling_BladeAuthor Commented:
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.
0
 
Sling_BladeAuthor Commented:
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
0
 
Sling_BladeAuthor Commented:
Of course it works anyway!!

Thanks Heaps.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now