Jump to content

Recommended Posts

Posted

So, basically, i have a notepad file, with data in this format:

" Name Surname Age Sex DayofBirth MonthofBirth "

Age, dayofbirth and monthofbirth are integers, others are Strings. I want to read this file word by word, however with the functions i've found in the Help file, that's impossible, since i can either read the whole line with FileReadLine (don't want to do that, i want to read the Name, edit/use it, then read Surname, edit/use it and so on and so on), or i can read character by character by using FileRead (also useless, since i don't know how many characters a word in the file has).

I know a way to solve this, but in C++, i'd make a While Loop to read character by character until it encounters space and add character by character into a string.

However, i'm pretty much a beginner in AutoIt and don't know how to do it with AutoIt.

Any help would be much appreciated.

Posted

Can you show me an exact example of a line?

Like this

Name<tab>Surname<tab>Age<tab>Sex<tab>DayofBirth<tab>MonthofBirth<tab>

or

Name Surname Age Sex DayofBirth MonthofBirth

or are the spaces/characters between these information labels random?

like

Name    Surname  Age    Sex   DayofBirth MonthofBirth

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Posted (edited)

Try this:

#include <Array.au3>
#include <File.au3>
$hFile = FileOpen("Test.txt", 2)
For $i = 1 To 10
    _FileWriteToLine("Test.txt", $i, "Name" & $i & " Surname" & $i & " " & Random(10, 50, 1) & " M " & Random(1, 31, 1) & " " & Random(1, 12, 1))
Next
FileClose($hFile)

$hFile = FileOpen("Test.txt", 0)
Local $array[_FileCountLines("Test.txt") + 1][6]
$i = 0
While 1
    $line = FileReadLine($hFile)
    If @error = -1 Then ExitLoop
    $aTmp = StringSplit($line, " ")
    For $j = 1 To UBound($aTmp) - 1
        $array[$i][$j - 1] = $aTmp[$j]
    Next
    $i += 1
WEnd
ReDim $array[$i - 1][6]
FileClose($hFile)
_ArrayDisplay($array)

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted

Thanks for the help UEZ and AlmarM, with your help i've finished my script.

I learned some things from your code UEZ, i'm really grateful for your efforts.

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...