Jump to content

Need Help - Modify .txt


Recommended Posts

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
Link to comment
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!

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

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

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