Sign in to follow this  
Followers 0
Orbiter

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

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 this post


Link to post
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.

Share this post


Link to post
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
Sign in to follow this  
Followers 0