Sign in to follow this  
Followers 0
RAMMRODD

readfile and stringbetween help

5 posts in this topic

Im starting to play with the array command and Im having an issue with stringbetween and reading a file. I've messed with stringbetween so Im a little familiar with it, but importing text from a document is completely foreign. Plz help

#include <String.au3>
#include <array.au3>

$file = FileOpen("test.txt", 0)
While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
Wend
$aArray1 = _StringBetween($line, 'Before', 'After');
MsgBox(0, "Text Between Before and After:", $aArray1)

test.txt has

Before Before

Goal

After

Share this post


Link to post
Share on other sites



MsgBox(0, "Text Between Before and After:", $aArray1[0])

Share this post


Link to post
Share on other sites

==> Subscript used with non-Array variable.:

Right at the [0]

Im new to array's so plz point me towards anything I missed, wrong format wrong command anything....plz and thank you

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Learn error handling. You always need to check the result of a function that returns an array.

#include <String.au3>
#include <array.au3>

$sFile = FileRead("test.txt")
If Not @error Then
    $aBetween = _StringBetween($sFile, 'Before', 'After')
    If Not @error And IsArray($aBetween) Then
        _ArrayDisplay($aBetween)
    Else
        MsgBox(16, "Text Between Before and After:", "Not found")
    EndIf
Else
    MsgBox(16, "Error", "File not read")
EndIf
Edited by zorphnog

Share this post


Link to post
Share on other sites

Wow that worked great. So does that mean the $aBetween can then be used in another if statement? Im pretty sure it can but just double checking.

IF $aBetween > 50

then do something? I'd really like to figure some stuff out on my own, so if I could get a yes or no on this that'd be great...

thanks again

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