NotStr(Value, Delimited list of unique values, Delimiter) 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.
==> Too many parameters passed to function.
Specifically: Max(InStr(Z,(S)(D),0,0-LZ+LS+LD)?LS+LD+LD:0,InStr(Z,(D)(S),,LZ-LS) ?1:0,(Q:=InStr(Z,(D)(S)(D)))?Q+LD+LS+LD:0),1),((Q:=InStr(Z,D,,P1))?Q:LZ+1)-P1)
I don't know if you're running a different version of AHK but this function doesn't seem to work.
I don't know if you're running a different version of AHK but this function doesn't seem to work.
Yes. I was running Version 1.1.31.01. Just installed latest version for your sake and tested.
I'm unable to reproduce your error.
Re: NotStr() : Swtich betwen multiple states
Posted: 21 Apr 2020, 19:07
by boiler
He selectively pulled out a part of that line of code that doesn’t make sense as a stand-alone line because part of it belongs to the other Max() call and and the SubStr() call, which he left out of it.
Re: NotStr() : Swtich betwen multiple states
Posted: 21 Apr 2020, 20:54
by Delta Pythagorean
I used the full function and tested it in full and I could not get it to work. I did not edit the function itself.
Also, the error that I provided was copied from the debugger I'm using that displays the errors to a console.
Re: NotStr() : Swtich betwen multiple states
Posted: 21 Apr 2020, 21:23
by SKAN
@Delta Pythagorean Strange!
Before posting, I always test my functions in Ansi, Unicode 32/64 in Windows 7/10.
It would be helpful if somebody else can test and confirm if there is an error.
Re: NotStr() : Swtich betwen multiple states
Posted: 21 Apr 2020, 21:33
by boiler
No error here. Win10, 64-bit machine with Unicode 32-bit AHK, v1.1.32.00.
No error here. Win10, 64-bit machine with Unicode 32-bit AHK, v1.1.32.00.
Thank you.. much appreciated!
Re: NotStr() : Switch between multiple states
Posted: 22 Apr 2020, 00:57
by Delta Pythagorean
My apologies, I had a library that was included that replaced the Max function.
I'll have to look deeper into where that specific function is placed but the function does work for me.
TL;DR:
My fault, had a function somewhere that replaced a function.
Re: NotStr() : Switch between multiple states
Posted: 22 Apr 2020, 15:58
by SKAN
Delta Pythagorean wrote:
My apologies, I had a library that was included that replaced the Max function.
I'll have to look deeper into where that specific function is placed but the function does work for me.
Thanks for the clarification. Okay, I've removed Max() from NotStr()
You may try it now.
Re: NotStr() : Swtich betwen multiple states
Posted: 22 Apr 2020, 16:00
by SKAN
burque505 wrote:
Thanks, @SKAN.
Re: NotStr() : Switch between multiple states
Posted: 23 Apr 2020, 03:17
by neogna2
Nice function SKAN!
I didn't understand what it did on first read through, until I got to the examples. Perhaps this sentence could be updated?
NotStr() will return next key if first parameter (key) is matches a value. If match fails, the first value is returned.
"is matches" looks like a typo and the mix of the phrases key/value tripped me up at first.
On second thought, maybe CycleStr() or just Cycle() would be a more self-explanatory name for the function?
In case some other people also think of the terms "cycle" and "wrap around" when they're looking for the kind of thing your function does here is more text that will make search engines guide them to this thread.
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. Examples
NotStr() will return next key if first parameter (key) is matches a value. If match fails, the first value is returned.
"is matches" looks like a typo and the mix of the phrases key/value tripped me up at first.
On second thought, maybe CycleStr() or just Cycle() would be a more self-explanatory name for the function?
In case some other people also think of the terms "cycle" and "wrap around" when they're looking for the kind of thing your function does here is more text that will make search engines guide them to this thread.
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. Examples
Loop
MsgBox % item := NotStr(item, "A|B|CC|CC") ; skips second CC
Thank you for this. I too didn’t understand SKANs description.
Re: NotStr() : Switch between multiple states
Posted: 23 Apr 2020, 07:15
by boiler
I also think neogna2’s suggestions really make clear what the value of this function is, including the name of the function and especially the clear description and examples.
Re: NotStr() : Switch between multiple states
Posted: 23 Apr 2020, 07:17
by SKAN
@neogna2
Many thanks for the fantastic feedback.
I didn't understand what it did on first read through, until I got to the examples. Perhaps this sentence could be updated?
I thought the GUI demo will explain it all.
I will update it totally with your quote.
NotStr(Value, Delimited unique values, Delimiter)
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)
On second thought, maybe CycleStr() or just Cycle() would be a more self-explanatory name for the function?
In case some other people also think of the terms "cycle" and "wrap around" when they're looking for the kind of thing your function does here is more text that will make search engines guide them to this thread.
Actually I wanted to name the function Not() but since its a wrapper for SubStr() I had to Include the "Str" part.
Google will index this page in couple of days anyways and whatever you've suggested will be google-able.
Worth pointing out also that the values in the set must be unique.
Yes. I should have mentioned it. Values (Switch states) need to be unique.
MsgBox str_skip("a","a/b/c")
str_skip(t,s,k:="/") => (RegExMatch(k s k, "(" k "([^" k "]+))?.*" k t k "(([^" k "]+)" k ")?", t),t.value(4) or t.value(2))
Re: NotStr() : Switch between multiple states
Posted: 23 Apr 2020, 09:05
by SKAN
boiler wrote:I also think neogna2’s suggestions really make clear what the value of this function is,
Yes .I have re-quoted him in OP.
boiler wrote:including the name of the function
The function is modeled after Not operator and is a Str manipulation function and hence the name NotStr()
My first two examples show this.
boiler wrote:and especially the clear description and examples.
Yes. My description was bad . The cover of the book is also important.
But my My GUI based demo is a good example.. if only people reach that far!
MsgBox str_skip("a","a/b/c")
str_skip(t,s,k:="/") => (RegExMatch(k s k, "(" k "([^" k "]+))?.*" k t k "(([^" k "]+)" k ")?", t),t.value(4) or t.value(2))
Very nice!. I don't have tools to benchmark V2 scripts, so unable to compare it with mine.
Would be nice if the function could return the first value when t is blank.
Re: NotStr() : Switch between multiple states
Posted: 24 Apr 2020, 08:13
by SpeedMaster
Thanks for this usefull function
Is it also possible to add an option for the direction ?
NotStr(S:="", Z:="", D:="|", dir:="1")
dir = 1 ; cycle forward
dir = -1 ; cycle backward
dir = 0 ; reset/restore starting pos
Yes. My description was bad . The cover of the book is also important.
I think a function without it's description is almost a dead function.
I recomand to put the help and usage right above the function. good example : ST library https://www.autohotkey.com/boards/viewtopic.php?f=6&t=53
ST library is missing some of your functions so I added them into my personal ST library. ( I hope you don't mind. )