Jump to content

how to insert text in a line !


 Share

Recommended Posts

  • Moderators

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? :huh:

Aha, there is "_FileWriteToLine", which strangely enough does exactly what you require. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 by Fubarable
Link to comment
Share on other sites

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 by scila1996
Link to comment
Share on other sites

 

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

  • Moderators

scila1996,

 

Oh No

Oh Yes! :D

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

scila1996,

 

I tried

But obviously not very hard! :D

#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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 by Jonniy

Thanks for your help & have a good day. Yours sincerely, -Jonniy-  

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...