Replace Text in text file

Replace text in text file, can't get it to work.

Page 1 of 1

5 Replies - 1678 Views - Last Post: 14 April 2010 - 01:38 PM Rate Topic: -----

#1 MaxDes  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 14-April 10

Replace Text in text file

Posted 14 April 2010 - 11:08 AM

I am using the following code, but cannot get this to work. Any help is appreciated!!! Yes I googled. yes I tried to fix it on my own. FOr hours and hours now. Must be code blind or something.

Update: I have gotten it to work if the replacement is just of one word. so if the word test is replaced by mouse and the only thing in the file is the word test, it works.

How can I replace like this:

CH_IPVOD_filename.mpg > replace the CH_IPVOD_ with nothing for the result of:

filename.mpg

?

I would like to replace every instance of ch_ipvod_ with nothing.

Public Class Form4

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

        Dim fso, inputFile, outputFile
        Dim str As String
        Dim str1 As String
        Dim str2 As String
        Dim str3 As String

        fso = CreateObject("Scripting.FileSystemObject")
        inputFile = fso.OpenTextFile("c:\archive.txt", 1)
        str = inputFile.ReadAll
        str = str.Replace("CH_ipvod_", "")
        str1 = str.Replace("_t*.", ".")
        str2 = str1.Replace("_xSPA_", "_Spa_")
        str3 = str2.Replace(".ts", ".mpg")
        outputFile = fso.CreateTextFile("c:\archiveREPLACED.txt", True)
        outputFile.Write(str)
        outputFile.close()

    End Sub
End Class


This post has been edited by PsychoCoder: 14 April 2010 - 01:14 PM
Reason for edit:: Code tags added


Is This A Good Question/Topic? 0
  • +

Replies To: Replace Text in text file

#2 MaxDes  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 14-April 10

Re: Replace Text in text file

Posted 14 April 2010 - 11:53 AM

bump for new info
Was This Post Helpful? 0
  • +
  • -

#3 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1638
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Replace Text in text file

Posted 14 April 2010 - 01:14 PM

Stop bumping your thread. Everyone here is here as volunteers and it can take time to get a reply.
Was This Post Helpful? 0
  • +
  • -

#4 MaxDes  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 14-April 10

Re: Replace Text in text file

Posted 14 April 2010 - 01:20 PM

I understand everyone is a volunteer. I didn't just bump the same exact post.

I revamped my entire post with a bunch of new info. As it already had 8 views I was just making sure that it didn't get lost to the people that had already looked.

I'll refrain in the future.
Was This Post Helpful? 0
  • +
  • -

#5 ZRonZ  Icon User is offline

  • D.I.C Head

Reputation: 28
  • View blog
  • Posts: 206
  • Joined: 09-January 09

Re: Replace Text in text file

Posted 14 April 2010 - 01:32 PM

Quote

How can I replace like this:

CH_IPVOD_filename.mpg > replace the CH_IPVOD_ with nothing for the result of:

filename.mpg


Your code says:

str = str.Replace("CH_ipvod_", "") 



Change "CH_ipvod_" to "CH_IPVOD_"
Was This Post Helpful? 0
  • +
  • -

#6 MaxDes  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 14-April 10

Re: Replace Text in text file

Posted 14 April 2010 - 01:38 PM

Wow seriously. That worked. I didn't realize that it was caps sensitive. Thank you so much!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1