Jump to content

Recommended Posts

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
Posted

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

Posted

<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

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
×
×
  • Create New...