Jump to content

readfile and stringbetween help


Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

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