NotStr() is a wrapper for SubStr()
- neogna2 wrote:
The NotStr function cycles to the next value in a set of values, wrapping around the end.
First parameter is a value in the set.
Second parameter is the set, a string of delimited values.
Third parameter (optional) is for changing the default delimiter "|".
Examples:
NotStr("B", "A|B|C") returns "C".
NotStr("C", "A|B|C") returns "A" (wrap around)
Edit: Worth pointing out also that the values in the set must be unique, otherwise the function does not cycle in the way one might expect.
The function:
Code: Select all
NotStr(S:="", Z:="", D:="|") { ; NotStr v0.6b By SKAN on D34M/D34R @ tiny.cc/notstr
Local Q, LS:=StrLen(S), LZ:=StrLen(Z), LD:=StrLen(D), P1, P2, Q
Return SubStr(LZ?Z:1,(P1:=LS+LZ=0||S=Z?1:InStr(Z,(S)(D),0,0-LZ+LS+LD)?LS+LD+1:InStr(Z,(D)(S),0,LZ
-LS)?1:(Q:=InStr(Z,(D)(S)(D)))?Q+LD+LS+LD:1),(LS+LZ=0?2:S=Z?1:(Q:=InStr(Z,D,0,P1))?Q:LZ+1)-P1)
}
The function - Readable version
Functionality explained with examples:
In computing, toggle means switching between two states 0/1 True/False or On/Off
Here follows an infinite loop
Code: Select all
N := 0
Loop
MsgBox % N := not N
Here follows an infinite loop:
Code: Select all
N := 0
Loop
MsgbOX % N := NotStr(N, "1|2|3|0")
Here follows a GUI based demo: Use Alt+Arrows keys to adjust size of edit control.
Code: Select all
#NoEnv
#Warn
#SingleInstance, Force
Gui, -DPIScale
s := 11, DPI := A_ScreenDPI
Gui, Font, % "s" . s-( DPI<=96 ? 0 : DPI<=120 ? 1 : DPI<=144 ? 2 : 3), Calibri
Gui, Margin, 25, 15
Gui, Add, Text, xm ym w175 h30 0x200, SetBatchLines
Gui, Add, Text, xm wp h30 0x200, DetectHiddenWindows
Gui, Add, Text, xm wp h30 0x200, Process priority
Gui, Add, Button, x+10 ym w75 h30 gSubRoutine, % T1 := ""
Gui, Add, Button, wp hp gSubRoutine, % T2 := "Off"
Gui, Add, Button, wp hp w140 gSubRoutine, % T3 := "Normal"
Gui, Add, Text, xm , Use Alt+Arrow key to adjust the size of edit control
Gui, Add, Edit, xm w325 h120, Hello world!
Gui, Show,, NotStr() Demo
T4 := "", T5 := ""
Return
SubRoutine:
GuiControlGet, Button, Focus
Switch (Button)
{
case "Button1" :
{
GuiControl,,Button1, % T1 := NotStr(T1, "-1")
SetBatchLines, %T1%
}
case "Button2" :
{
GuiControl,,Button2, % T2 := NotStr(T2, "On|Off")
DetectHiddenWindows, %T2%
}
case "Button3" :
{
GuiControl,,Button3, % T3 := NotStr(T3, "Low BelowNormal Normal AboveNormal High", " ")
Process,Priority,, %T3%
}
}
Return
EditWidth:
Switch (A_ThisHotkey)
{
Case "!Right" : GuiControl,Move,Edit1, % T4 := NotStr(T4, "w425 w525 w625 w700 w900 w325", " ")
Case "!Left" : GuiControl,Move,Edit1, % T4 := NotStr(T4, "w900 w700 w625 w525 w425 w325", " ")
Case "!Up" : GuiControl,Move,Edit1, % T5 := NotStr(T5, "h180 h240 h320 h480 h120", " ")
case "!Down" : GuiControl,Move,Edit1, % T5 := NotStr(T5, "h480 h320 h240 h180 h120", " ")
}
Gui, Show, Center AutoSize
Return
#IfWinActive NotStr() Demo ahk_class AutoHotkeyGUI
!Right:: GoSub, EditWidth
!Left:: GoSub, EditWidth
!Up:: GoSub, EditWidth
!Down:: GoSub, EditWidth
#IfWinActive