Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

remove text from file useng visual basic?

how do i remove the specified text from a text file with out altering any of the other text surrounding it?

Update:

The code that snimont gave me changes the entire file. i only want it to change some of the text with out effecting the other text

2 Answers

Relevance
  • 1 decade ago
    Favorite Answer

    Using Vb.Net

    Dim strFilePath As String = "C:\text.txt"

    Dim strFileContents As String

    strFileContents = My.Computer.FileSystem.ReadAllText(strFilePath)

    Dim strFind As String = "your word/words here"

    Dim intStart As Integer = InStr(strFileContents, strFind)

    Dim strNewfileContents As String = strFileContents.Remove(intStart - 1, strFind.Length + 1)

    My.Computer.FileSystem.WriteAllText(strFilePath, strNewfileContents, False)

  • 1 decade ago

    one way to do it if it's o small text file is; parse the string into an array, find and remove the unwanted text, reconstruct the string and recreate the file

Still have questions? Get your answers by asking now.