StrQ() maintains a pipe delimited (FIFO) queue of (unique) strings
Parameters:
- List The variable containing queue
Item A new (unique) string to be added to the top of list. An existing item will be bumped to the top.
Max String capacity of Queue
D Item Delimiter. Default is pipe "|".
Code: Select all
StrQ(Q, I, Max:=10, D:="|") { ; StrQ v.0.90, By SKAN on D09F/D34N @ tiny.cc/strq
Local LQ:=StrLen(Q), LI:=StrLen(I), LD:=StrLen(D), F:=0
Return SubStr(Q:=(I)(D)StrReplace(Q,InStr(Q,(I)(D),,0-LQ+LI+LD)?(I)(D):InStr(Q,(D)(I),0,LQ
-LI)?(D)(I):InStr(Q,(D)(I)(D),0)?(D)(I):"","",,1),1,(F:=InStr(Q,D,0,1,Max))?F-1:StrLen(Q))
}
; Usage examples:
#SingleInstance, Force
MAXQ := 10
Que := ""
Loop 9
Que := StrQ( Que, "Item" A_Index, MAXQ, "`n" )
MsgBox % Que
Que := StrQ( Que, "Item10", MAXQ, "`n" ) ; add a new item to Que
MsgBox % Que
Que := StrQ( Que, "Item11", MAXQ, "`n" ) ; add a new item to Que.. oldest item "Item1" is dequeued
MsgBox % Que
Que := StrQ( Que, "Item5", MAXQ, "`n" ) ; Bump up an existing item to top of Que
MsgBox % Que
MAXQ := 5 ; Reduce capacity of Queue
Que := StrQ( Que, "`n", MAXQ, "`n" ) ; Apply the changes, Note: Parameter 2 should be the delimiter
MsgBox % Que
Latest := StrQ( Que,"`n", 1, "`n" ) ; Retrieve the "top-most = latest = first" item in queue
MsgBox % Latest
GUI based example:
Code: Select all
#NoEnv
#SingleInstance, Force
MAXQ := 14
Fruits := "Apple|Banana|Cherry|Durian|Fig|Grape|Kumquat|Lychee|Mango|Nectarine|Orange|Papaya|Quince|Yuzu"
Gui, Font, S11, Calibri
Gui, Margin, 5, 5
Gui, Add, Text, xm ym w400, Type a string and press <Enter>
Gui, Add, ComboBox, xm y+5 wp r14 Simple vChoice, %Fruits%
Gui, Add, Button, xm+10 y+10 w100 h24 Default gSelFruit, Add/Select
Gui, Show,,StrQ() demo
Return
GuiClose:
ExitApp
SelFruit:
GuiControlGet, Choice
StringReplace, Choice, Choice, |,, All ; Delimiter shouldn't be present in string
Fruits := StrQ( Fruits, Choice, MAXQ )
GuiControl,, Choice, % "|" Fruits
Return
FileQ() Removes non-existent file paths from a queue
Parameters:
- List The variable containing queue
Folder Optional. A common prefix like "F:" or "D:\My folder". Depends on how you queued file paths.
D Item Delimiter. Default (and suggested) is pipe "|".
Function ( w/ usage examples)
Code: Select all
FileQ( List, Folder := "", D := "|" ) { ; by SKAN | 01-Oct-2018 | Topic: goo.gl/R4QrF4
Local NewList := "", F := ( Folder<> "" ? Folder "\" : "" )
Loop, Parse, List, %D%
If FileExist( F A_LoopField )
NewList .= A_LoopField D
Return RTrim( NewList,D )
}
; Usage example
#NoEnv
#SingleInstance, Force
FileList := "asd.txt|fgh.ahk|Installer.ahk|license.txt|AutoHotkey.chm|qwerty"
SplitPath, A_AhkPath,, Folder
MsgBox % FileQ( FileList, Folder )