Followers 0

# Need Help - Modify .txt

## 9 posts in this topic

#1 ·  Posted (edited)

I have a huge .txt with names (each name begins on a new line) I would like to put into an array. The way I thought of doing this was to write a small program that modifies the existing .txt and adds [0], [1] etc in front of all the names.

Problem is that I cannot seem to get the array number in front of the names, they either replace the line, or generates a new line.

Snippet:

#Include <file.au3>
$lines = 1000$File = FileRead("C:\Users\Administrator\Desktop\text.txt")
For $i = 1 to$lines
FileWriteLine("C:\Users\Administrator\Desktop\text.txt", "[" & $i &"]") Next I have tried this also with the _FileWriteToLine function. #Include <file.au3>$lines = 1000
$File = FileRead("C:\Users\Administrator\Desktop\text.txt") For$i = 1 to $lines _FileWriteToLine("C:\Users\Administrator\Desktop\text.txt",$i ,"[" & $i &"]") Next Edited by Orbiter #### Share this post ##### Link to post ##### Share on other sites _FileReadToArray() Won't that put all the names into just one array? #### Share this post ##### Link to post ##### Share on other sites It does not look like you have a FileOpen in your script. Don't forget to open it in write mode. 010101000110100001101001011100110010000001101001011100110010000 001101101011110010010000001110011011010010110011100100001 My Android cat and mouse game https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek We're gonna need another Timmy! #### Share this post ##### Link to post ##### Share on other sites To clarify: I have a .txt file formatted like this Aarne Aaron Aase Aba Abai Abaoub Abas Abay AbayomiAbaz AbayomiAbazaj I need a macro or script that converts the .txt file into something like this: [0]Aarne [1]Aaron [2]Aba [3]Abai [4]Abaoub #### Share this post ##### Link to post ##### Share on other sites #7 · Posted (edited) <br>_FileReadToArray()<br> <br>names.txt Aarne Aaron Aase Aba Abai Abaoub Abas Abay AbayomiAbaz AbayomiAbazaj #include <file.au3> #include <array.au3> Local$aNames
_FileReadToArray("names.txt",$aNames) _ArrayDisplay($aNames)

</array.au3></file.au3>

Edited by somdcomputerguy

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

##### Share on other sites

<br>names.txt

Aarne
Aaron
Aase
Aba
Abai
Abaoub
Abas
Abay
AbayomiAbaz
AbayomiAbazaj

#include <file.au3>
#include <array.au3>

Local $aNames _FileReadToArray("names.txt",$aNames)
_ArrayDisplay(\$aNames)

</array.au3></file.au3>

Thank you very much

##### Share on other sites

Well you're welcome, but LaCastiglione posted an hour before I did the function needed..

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.