Changing a word in a .txt document with VB.net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • spazzo6281
    New Member
    • Feb 2008
    • 13

    Changing a word in a .txt document with VB.net

    Hello, does anybody out there know how to change a single word in a text document. Right now I'm using VB.net to read a word in a text document (it's the only word in there), I would like to be able to change that word using visual basic. Any help will be greatly appreciated.
  • Tenneyson
    New Member
    • Apr 2008
    • 17

    #2
    Originally posted by spazzo6281
    Hello, does anybody out there know how to change a single word in a text document. Right now I'm using VB.net to read a word in a text document (it's the only word in there), I would like to be able to change that word using visual basic. Any help will be greatly appreciated.


    Hi

    Please submit what you have written so far

    regards

    Comment

    • spazzo6281
      New Member
      • Feb 2008
      • 13

      #3
      Originally posted by Tenneyson
      Hi

      Please submit what you have written so far

      regards
      The code that i'm using to read the word is
      Code:
      My.Computer.FileSystem.ReadAllText(file path)
      . I have nothing written yet for changing the word. I really don't know how to go about doing that part.

      Comment

      • jamesd0142
        Contributor
        • Sep 2007
        • 471

        #4
        I wud:...

        1. Read the whole file
        2. process it in vb
        3. truncate the file
        4. write the new data back to the file

        Comment

        • ShadowLocke
          New Member
          • Jan 2008
          • 116

          #5
          Maybe this will help:

          http://bytes.com/forum/thread788846-save+text.html

          Comment

          • spazzo6281
            New Member
            • Feb 2008
            • 13

            #6
            Thanks for you help but for some reason I just can't figure it out. This is the code i have so far:

            Code:
            my.computer.filesystem.readalltext("I:\msctc moorhead archive\word.txt")
            This is reading the text document that contains the word "test"

            How would I go about changing that word using textboxes in VB.net.

            Comment

            • spazzo6281
              New Member
              • Feb 2008
              • 13

              #7
              I have gotten the code figured out. This is what it wound up being:

              Code:
              Dim text1 As String = txtOldP.Text
                          Dim text2 As String = txtNewP1.Text
                          Dim pword As String = My.Computer.FileSystem.ReadAllText("I:\MSCTC Moorhead Archive\word.txt", System.Text.ASCIIEncoding.ASCII)
                          My.Computer.FileSystem.WriteAllText("I:\MSCTC Moorhead Archive\word.txt", pword.Replace(txtOldP.Text, txtNewP1.Text), False)
              Thanks to those who helped.

              Comment

              Working...