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)?
SaaDwTk
0
Newbie Poster
Recommended Answers
Jump to PostRead 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).
Jump to PostPublic 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
All 5 Replies
Reverend Jim
4,780
Hi, I'm Jim, one of DaniWeb's moderators.
Moderator
Featured Poster
SaaDwTk
0
Newbie Poster
SaaDwTk
0
Newbie Poster
SaaDwTk
0
Newbie Poster
Reverend Jim
4,780
Hi, I'm Jim, one of DaniWeb's moderators.
Moderator
Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.