scila1996 Posted February 22, 2014 Share Posted February 22, 2014 I have a text file abc.txt Your Hello Hanoi University of Technology Department of information technology Text 1 ... Text 1 ... Text n ... How to insert the words "I am Trung Nguyen on the 2nd line Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 22, 2014 Moderators Share Posted February 22, 2014 scila1996,You want to write a specific line to a file - I wonder if there is a function in the Help file that looks as if it might help you? Aha, there is "_FileWriteToLine", which strangely enough does exactly what you require. M23 McMuffinTop and Fubarable 2 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Fubarable Posted February 22, 2014 Share Posted February 22, 2014 (edited) What have you tried so far? If this were my project, I'd consider using: FileOpen: to open the file to read and the file to write to FileReadLine: to read each line of the file of the input file FileWriteLine: to write each line from the input file to the output file I'd also use FileWriteLine to write the additional line of interest FileFlush: This may be needed to flush the buffers and write all to the output file FileClose: to close both input and output files. Then you will probably want to delete the input file and rename the output file to match the original file. Oops, I missed _FileWriteToLine as noted by Melba, a function that would simplify all of this... D'oh! Edited February 22, 2014 by Fubarable Link to comment Share on other sites More sharing options...
scila1996 Posted February 22, 2014 Author Share Posted February 22, 2014 (edited) Oh No I know this syntax. But I mean - I have 3 lines of text including Line 1: Hello Line 2: I Am Trung Nguyen Line 3: Polytechnic University I want to put this text into "Information Technology Department" ---> insert into 2 lines like this. Line 1: Hello Line 2: Faculty of Information Technology Line 3: I Am Trung Nguyen Line 4: Polytechnic University Edited February 22, 2014 by scila1996 Link to comment Share on other sites More sharing options...
Hypnotik Posted February 22, 2014 Share Posted February 22, 2014 Oh No I know this syntax. But I mean - I have 3 lines of text including I want to put this text into "Information Technology Department" ---> insert into 2 lines like this. _FileWriteToLine("Ur file path", number of line i want to insert it, "What i want to insert", 0) ;Pratic Example _FileWriteToLine("c:\test.txt", 3, "blablabla", 0) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 22, 2014 Moderators Share Posted February 22, 2014 scila1996, Oh NoOh Yes! The _FileWriteToLine function I recommended is exactly what you want - have you tried it? Post the code you used if it did not work. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
scila1996 Posted February 22, 2014 Author Share Posted February 22, 2014 I tried and was But what I want is > Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 22, 2014 Moderators Share Posted February 22, 2014 scila1996, I triedBut obviously not very hard! #include <File.au3> $sFile = "Test.txt" FileWrite($sFile, "Hello" & @CRLF & "I Am Trung Nguyen" & @CRLF & "Polytechnic University") MsgBox(0, "Original", FileRead($sFile)) _FileWriteToLine($sFile, 2, "Faculty of Information Technology") MsgBox(0, "Amended", FileRead($sFile)) FileDelete($sFile)Does that work for you? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Jonniy Posted February 22, 2014 Share Posted February 22, 2014 (edited) You can try to think at least a bit. What you want is to insert text at a specific line correct? So why do you think that the suggested function is not the correct one? Doesn't seem like you have tried at all. #include <File.au3> $sFile = @AppDataDir & "\test12345.txt" $hFile = FileOpen($sFile, 10) FileWrite($hFile, "line 1" & @CRLF & "line 2" & @CRLF & "line 3" & @CRLF & "line 4" & @CRLF & "line 5") FileClose($hFile) $iTargetLine = 4 $sTargetString = "This gets inserted" _FileWriteToLine($sFile, $iTargetLine, $sTargetString) ShellExecute($sFile) MsgBox(0, "", "Result", 5) FileDelete($sFile) Seems like Melba beat me. Edited February 22, 2014 by Jonniy Thanks for your help & have a good day. Yours sincerely, -Jonniy- Link to comment Share on other sites More sharing options...
scila1996 Posted February 23, 2014 Author Share Posted February 23, 2014 sorry I have little misunderstanding and has more parameters after 1 Thank M23 Link to comment Share on other sites More sharing options...
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