Jump to content

Recommended Posts

Posted

Is there a way to separate the way an entry is read into the array?

So basically instead of it determining one array value by line, it'll determine it by an ascii character?

I'm not sure if I'm being clear here.....but let me create an example

Normally _FileReadToArray will read each line and put them into array values

value1
value2
value3
value4

What I want to do is determine values by using an ascii character such as this [ or (

(va
lue1)

(v
a
l
u
e
2)

(valu
e3)

Where in the second example each value would be determined as a value if it was between the two ( )

Posted

one thing you could do, is replace all the line breaks with "", so the whole file becomes 1 line, then Replace all instances of "(" or ")" with @CRLF.

then write that to a temp file, then _FileReadToArray() that file.

Posted (edited)

Here's one way to do it:

EDIT: Okay, make that another way :)

Dim $data, $index, $values[1], $temp

$data = FileRead("Test.dat"); read in the data file
$data = StringReplace($data, @CRLF, ''); nuke the line breaks

$index = 1
While StringInStr($data, ")"); The assumption is that if ')' exists, we've got another value yet
    $temp = StringRegExp($data, '(?U)\((.*)\)', 1)
    $index += 1
    ReDim $values[$index + 1]
    $values[0] = $index - 1
    $values[$index] = $temp[0]
    $data = StringTrimLeft($data, StringLen($temp[0]) + 2)
WEnd

Contents of "Test.dat"

(va
lue1)

(v
a
l
u
e
2)

(valu
e3)

Note that $values[0] contains the number of values found in "Test.dat". All that's left to do is whatever parsing you wanted.

Also, make sure you double-check how line breaks are formatted. You may need to use @LF instead of @CRLF.

Edited by Artisan
  • Moderators
Posted

Local $a_array = _mySplit($s_my_string, "(", ")")

Func _mySplit($s_string, $s_front_delim, $s_back_delim, $b_no_line_break = True)
    If $b_no_line_break Then
        Return StringRegExp(StringRegExpReplace($s_string, "\r|\n", ""), _
            "\" & $s_front_delim & "(.*?)" & "\" & $s_back_delim, 3)
    EndIf
    Return StringRegExp("\" & $s_front_delim & "(.*?)" & "\" & $s_back_delim, 3)
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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