Jump to content


Photo

loop, parse [backwards]


  • Please log in to reply
10 replies to this topic

#1 Azevedo

Azevedo
  • Members
  • 59 posts

Posted 02 June 2012 - 07:00 PM

Hey folks!

Is it possible to loop parse backwards?
I tried the following but won't work

Colors = red,green,blue
Loop, parse, Colors
{
    MsgBox, Color number %A_Index% is %A_LoopField%.
    if (...)
        [color=#FF0000]%A_Index%--[/color] [color=#00BF00]; repeat latest %A_LoopField%.[/color]
}

thanks!

#2 Learning one

Learning one
  • Members
  • 1294 posts

Posted 02 June 2012 - 07:06 PM

Yes. Look here.

#3 Guests

  • Guests

Posted 02 June 2012 - 07:09 PM

Colors = red,green,blue

Loop, parse, Colors

{

    MsgBox, Color number %A_Index% is %A_LoopField%.

    if (...)

         ... ; action with priorLoopField

    priorLoopField := A_LoopField ; in the end of loop

}


#4 Azevedo

Azevedo
  • Members
  • 59 posts

Posted 03 June 2012 - 01:24 AM

Cheers!

#5 Leef_me

Leef_me
  • Moderators
  • 7704 posts

Posted 03 June 2012 - 04:52 AM

; code removed for brevity


Hey Guest,
Can you show an example of how that works ?

Even "msgbox % priorLoopField" doesn't seem to work as OP inteded.

#6 Guests

  • Guests

Posted 03 June 2012 - 10:24 AM

%A_Index%-- ; repeat latest %A_LoopField%.

Colors = red,green,blue
Loop, parse, Colors, `,
{
    MsgBox, Current A_LoopField is %A_LoopField%.
    if (A_LoopField = "blue") ; or any other expression
        MsgBox Prior A_LoopField was %priorLoopField%
    priorLoopField := A_LoopField
}


#7 hd0202

hd0202
  • Members
  • 453 posts

Posted 03 June 2012 - 10:50 AM

Try this:
Colors = red,green,blue

Loop, parse, Colors, `,

    forsort .= a_index "/" a_loopfield ","

sort, forsort, N R D,

stringtrimright, forsort, forsort, 1

loop, parse, forsort, `,

{

    stringsplit, color, a_loopfield, /

    MsgBox, Current Color is %color2%

}
Hubert

#8 VxE

VxE
  • Fellows
  • 3505 posts

Posted 03 June 2012 - 07:06 PM

http://www.autohotke...=530232#p530232

#9 sinkfaze

sinkfaze
  • Moderators
  • 6087 posts

Posted 03 June 2012 - 07:20 PM

If you're going to use StringSplit you may as well use it from the beginning:

Colors = red,green,blue
StringSplit, n, Colors, `,
Loop %	n%0%
{
	a :=	n%0% + 1 - A_Index
	MsgBox %	"Current color is " n%a% "."
}


#10 jethrow

jethrow
  • Fellows
  • 2549 posts

Posted 04 June 2012 - 05:55 AM

... could also push the colors to an array, & then enumerate it:
Colors = red,green,blue

array := []



Loop Parse, Colors, `,

   array.insert(1, A_LoopField)

For Each, color in array

   MsgBox %   "Current color is " color "."


#11 sinkfaze

sinkfaze
  • Moderators
  • 6087 posts

Posted 04 June 2012 - 06:40 AM

Here's an interesting way to do it using RegExMatch and the Occurrence parameter of InStr:

Colors=red,green,blue
StringReplace, Colors, Colors, `,, `,, UseErrorLevel
Loop %	(c :=	ErrorLevel + 1)
{
	RegExMatch(Colors,"[^,]+",item,(A_Index=c) ? 1 : InStr(Colors,",",0,1,c-A_Index))
	MsgBox %	item
}