Jump to content

Append to line in file


 Share

Go to solution Solved by Malkey,

Recommended Posts

Hello!

at once - sorry for my bad engilshi.. is my hmm.. second language.

Ok, i have a problem: 

I must append to line in txt

i.e (google translator :P

i have in file: 

word

word

word

and now i wants append:   (word1 form input)

word1 word

word1 word

word1 word 

I hope it is well described (google translator) 

Im try add to array but still do not know how to do it

 

at once
at once
at once
at once 
 
at once
 
at once
 

 

Link to comment
Share on other sites

how about

#include <File.au3>
_FileCreate("test.txt")
FileWrite("test.txt","word1" & @CRLF & "word1" & @CRLF & "word1" & @CRLF )
Local $a[1]
_FileReadToArray("test.txt",$a)
For $i = 1 To UBound($a)-1
    $a[$i] &= " word"
Next
_FileWriteFromArray("test.txt",$a,1)
ConsoleWrite(FileRead("test.txt") & @CRLF)
Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

  • Solution

Using the word "append to line" insinuates hanging something onto the end of the line.
Your example shows prepending to the lines. That is, adding to the beginning of each line.

So, here is an example of adding "word1 " to the beginning of each line in a file.

#include <Array.au3>
#include <File.au3>

_FileCreate("test.txt")
FileWrite("test.txt", "word" & @CRLF & "word" & @CRLF & "word")
Local $a[1]
_FileReadToArray("test.txt", $a)
_ArrayDisplay($a)
For $i = 1 To UBound($a) - 1
    $a[$i] = "word1 " &  $a[$i] ; Prepend "word1 " to each array element.
Next
_FileWriteFromArray("test.txt", $a, 1)
ConsoleWrite(FileRead("test.txt") & @CRLF)
Link to comment
Share on other sites

or he wants "1 word" appended...

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

Don't think so:

 

and now i wants append:   (word1 form input)

 

Looks like he means prepending/prefixing "word1 " indeed, as in "word1 <form input>"

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

 

Using the word "append to line" insinuates hanging something onto the end of the line.

Your example shows prepending to the lines. That is, adding to the beginning of each line.

So, here is an example of adding "word1 " to the beginning of each line in a file.

#include <Array.au3>
#include <File.au3>

_FileCreate("test.txt")
FileWrite("test.txt", "word" & @CRLF & "word" & @CRLF & "word")
Local $a[1]
_FileReadToArray("test.txt", $a)
_ArrayDisplay($a)
For $i = 1 To UBound($a) - 1
    $a[$i] = "word1 " &  $a[$i] ; Prepend "word1 " to each array element.
Next
_FileWriteFromArray("test.txt", $a, 1)
ConsoleWrite(FileRead("test.txt") & @CRLF)

Dude you are the best! Thenks all! :) 

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...