0

How can I write to a specific line in a text file?
Can someone make me a function sWrite(filePath as string, noLine as integer, newText as string)?

2
Contributors
5
Replies
7
Views
4 Years
Discussion Span
Last Post by Reverend Jim
0

Read the entire file into a text array (System.IO.File.ReadAllLines). Replace the specific entry in the text array, then write the array back to the file (System.IO.File.WriteAllLines).

0

@Reverend Jim, could you please give me some code snippet?

0

I have to use it in multiple files, so I cant get reference checking if line.has(specific text)

0

Is it right?

    Public Function writeFile(filePath As String, noLine As Integer, newText As String)
        Dim lines() As String = IO.File.ReadAllLines(filePath)
        lines(noLine) = newText

        Return Nothing
    End Function
1
Public Sub writeFile(filePath As String, noLine As Integer, newText As String)
    Dim lines() As String = IO.File.ReadAllLines(filePath)
    lines(noLine) = newText
    IO.File.WriteAllLines(filepath,lines)
End Sub
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.