87450kalle Posted September 12, 2005 Posted September 12, 2005 Hi, I am writing a program where I want to replace a specific line in a txt file. I know the line number that i want to replace but I dont know how to get the program to replace it with my new text line. Appreciate any suggestions... /Johan
ning Posted September 12, 2005 Posted September 12, 2005 ; read in the file $list = FileRead ($filename, FileGetSize ($filename)) If @error = 1 Then MsgBox (0, "", "Error reading from " & $filename) Exit 1 EndIf ; split into lines $list = StringSplit ($list, @CRLF, 1) ; replace specific line $linenum = 50 $list[$linenum] = "This is the text on the replaced line." ; overwrite the file $handle = FileOpen($filename, 1) If $handle = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit 1 EndIf For $i = 1 To $list[0] FileWriteLine ($handle, $list[$i]) Next FileClose($handle) How's that? Should be fairly self-explanatory I think...
/dev/null Posted September 12, 2005 Posted September 12, 2005 Hi,I am writing a program where I want to replace a specific line in a txt file.I know the line number that i want to replace but I dont know how to get the program to replace it with my new text line.Appreciate any suggestions.../Johan<{POST_SNAPBACK}>If you know the content of the line you could use _ReplaceStringInFile().CheersKurt __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now