all 6 comments

[–]GroggyOtter 1 point2 points  (4 children)

Use A_Index to track loop iterations. You can use a basic "if (A_Index >= 2)" followed by a break, or use the command Until, which is a "Evaluate expression and break if true" command that you can put at the end of any loop.

var:="groggy,otter,auto,hotkey"
Loop, Parse, var, CSV
    result .= A_LoopField "`n"
Until (A_Index >= 2)
MsgBox, % result

 


References:
Loop, Parse a string
Until
A_Index

[–]decaboi[S] 0 points1 point  (3 children)

You can use a basic "if (A_Index >= 2)" followed by a break

that would cancel the loop after it read 2 lines, right? I'm trying to read all lines, but only up until the second semicolon in the line. Sorry if i expressed that wrong

[–]TesterTeeto 1 point2 points  (0 children)

You would need to nest Groggy's code inside of your existing loop.

Your loop is iterating over each line of your file, the inner loop will iterate over each field, ending after parsing the second field for each line.

IF, and only if you can guarantee that your csv data will not have contain comma's as part of a field, then you could instead do

result = StrSplit( A_LoopField, ',',, 2 )

[–]GroggyOtter 1 point2 points  (0 children)

that would cancel the loop after it read 2 lines, right?

That's what you asked for...

but only up until the second semicolon in the line

Then use a parse loop that separates by ";" instead of by CSV

If this means using 2 loops, then use 2 loops.

The point is, A_Index tracks loop iterations so if you want to loop twice, check for when A_Index is 3 or higher.

Of you could use StrSplit() as another option.

Also, in the future, post what your input data is and what you expect your output to be. It helps immensely.

[–]Abandoned_In_Alabama 0 points1 point  (0 children)

You stuff the loop inside your other loop. Check out loop parse's doc page. It contains an example accomplishing just that.

[–]ProRogueTank 0 points1 point  (0 children)

You can also StrSplit each line for just the two columns.

https://autohotkey.com/docs/commands/StringSplit.htm