If (Var == "value1|value2|value3")
-
- Posts: 1416
- Joined: 04 Nov 2008 05:35
- Location: Hanoi, Vietnam
If (Var == "value1|value2|value3")
I remembered this works before:
If("<curext>" == "docx|doc|xlsx|xls") {msg ok}
But it doesn't now. Anything wrong?
Besides, where is this kind of comparision documented in help file?
If("<curext>" == "docx|doc|xlsx|xls") {msg ok}
But it doesn't now. Anything wrong?
Besides, where is this kind of comparision documented in help file?
I'm a casual coder using AHK language. All of my xys scripts:
http://www.xyplorer.com/xyfc/viewtopic. ... 243#p82488
http://www.xyplorer.com/xyfc/viewtopic. ... 243#p82488
Re: If (Var == "value1|value2|value3")
Shouldn't it be
Code: Select all
If("<curext>" == "docx" | "<curext>" == "doc" | "<curext>" == "xlsx" | "<curext>" == "xls") {msg ok}
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]
Don sees all [cit. from viewtopic.php?p=124094#p124094]
Re: If (Var == "value1|value2|value3")
E.g.:Anything wrong?
Code: Select all
If("docx|doc|xlsx|xls" LikeI "*<curext>*") {msg ok}
Code: Select all
where is this kind of comparision documented in help file?
One of my scripts helped you out? Please donate via Paypal
-
- Posts: 1416
- Joined: 04 Nov 2008 05:35
- Location: Hanoi, Vietnam
Re: If (Var == "value1|value2|value3")
Thanks, I know both these methods but think that If(Var == "value1|value2|value3") would be better. I did saw this kind of expression in a xys script somethime ago aghhh.
If("docx|doc|xlsx|xls" LikeI "*ocx*") would result in True eventhough I want "docx".
If("<curext>" == "docx" | "<curext>" == "doc" | "<curext>" == "xlsx" | "<curext>" == "xls") is accurate, but too lenghthy
If("docx|doc|xlsx|xls" LikeI "*ocx*") would result in True eventhough I want "docx".
If("<curext>" == "docx" | "<curext>" == "doc" | "<curext>" == "xlsx" | "<curext>" == "xls") is accurate, but too lenghthy
I'm a casual coder using AHK language. All of my xys scripts:
http://www.xyplorer.com/xyfc/viewtopic. ... 243#p82488
http://www.xyplorer.com/xyfc/viewtopic. ... 243#p82488
Re: If (Var == "value1|value2|value3")
Which can be corrected by surrounding the needle and haystack with the separator like so:binocular222 wrote:I did saw this kind of expression in a xys script somethime ago aghhh.
If("docx|doc|xlsx|xls" LikeI "*ocx*") would result in True eventhough I want "docx".
Code: Select all
if ("|docx|doc|xlsx|xls|" LikeI "*|ocx|*")
Maybe something like:
Code: Select all
FindToken(token, list, [separator=" "], [flags=iw]);
Flags:
i = Case Insensitive
r = Return index from end.
w = Use wildcards (If missing then token is treated literally. If included and token does not contain wildcards treat it as *token*.)
Returns:
0 = If token was not found in the list.
Otherwise return the index of the token within the list.
-
- Posts: 855
- Joined: 05 Oct 2011 13:15
Re: If (Var == "value1|value2|value3")
Always eager when someone's talking about a new toy!TheQwerty wrote:FindToken(token, list, [separator=" "], [flags=iw]);
In this case, what would be the difference with strpos()?
BTW, especially with Like, I'm a partisan of the "surrounding the needle and haystack with the separator" too. It doesn't always feel "clean", but it feels "safe"!
PS: I don't add anything to the OP since the collective answers already sum it quite well...
• Scripts: Session Manager | SlideShow | Collection Manager | Power Launcher | Akelpad syntax highlighting | ...
Re: If (Var == "value1|value2|value3")
StrPos() returns the first matching position within a string and is zero-based.FluxTorpedoe wrote:Always eager when someone's talking about a new toy!TheQwerty wrote:FindToken(token, list, [separator=" "], [flags=iw]);
In this case, what would be the difference with strpos()?
FindToken() returns the first matching token index within the list and is one-based.
Code: Select all
$haystack = 'a b c d';
$needle = 'c';
$strPos = StrPos($haystack, $needle); // == 4. It is the fourth character.
$tokPos = FindToken($needle, $haystack); // == 3. It is the third token.
And yes this is just a function to replace a rather simple while/foreach loop, but being a function allows it to be better used in conditionals. Alternately the ability to create users functions would obviate the need for this function.
-
- Site Admin
- Posts: 60635
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: If (Var == "value1|value2|value3")
I somehow don't get the use of FindToken. When you look for a token in a string, you already know that token (else you cannot look for it). So what use is it to get the position of that token? Isn't it enough to know that the token is somewhere in the string? (for which strpos() is enough)
FAQ | XY News RSS | XY Twitter
Re: If (Var == "value1|value2|value3")
Because knowing the position of the token makes it easier to then retrieve/act on the previous or next token - something that strpos is not especially helpful with.admin wrote:I somehow don't get the use of FindToken. When you look for a token in a string, you already know that token (else you cannot look for it). So what use is it to get the position of that token? Isn't it enough to know that the token is somewhere in the string? (for which strpos() is enough)
Say I'm using a set of tags to mark the state of a file: "idea|designed|developed|complete".
And I want a script to move all selected items to the next state.
Strpos isn't well suited for this.
Instead you'd likely write a separate script that accepts a list and a token.
It loops through the list to find the token and either "returns" the index or the next token.
Similarly as this thread shows, using only StrPos to locate a token within a list means that you have to give some consideration to whether your needle could be part of another token within the haystack and you must thus take care to do something to guarantee a correct match. With FindToken disable the wildcards and that issue should be lessened or non-existent.
Further, with the wildcard support FindToken becomes easier than using a regular expression to access data which might be stored in a dictionary or tabular format (especially for those not comfortable with regex).
Code: Select all
$dict = "Blue;12|Red;15|Green;28";
$clr = Input("Input the name of a color:",,"red");
$idx = FindToken("$selectedColor;*", $dict, '|');
if ($idx > 0) {
$clrData = GetToken($dict, $idx, "|");
$clrCount = GetToken($clrData, 2, ";");
} else {
$clrCount = "no";
}
Echo "There are $clrCount $clr item(s).";
-
- Site Admin
- Posts: 60635
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: If (Var == "value1|value2|value3")
OK, makes sense. Maybe TokenPos or TokenIndex or GetTokenIndex would be a better name?
FAQ | XY News RSS | XY Twitter
Re: If (Var == "value1|value2|value3")
What's wrong with FindToken?admin wrote:OK, makes sense. Maybe TokenPos or TokenIndex or GetTokenIndex would be a better name?
I'm not really partial to the name..
GetTokenIndex is okay because that puts it near GetToken.
TokenPos is okay because it is similar in function to StrPos.
Not a fan of TokenIndex and not sure why.
-
- Site Admin
- Posts: 60635
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: If (Var == "value1|value2|value3")
I prefer GetTokenIndex. In the meantime I coded the function in VB and it works nicely. Not sure if I find the time to add it to scripting before 13.00.
FAQ | XY News RSS | XY Twitter
Re: If (Var == "value1|value2|value3")
13.00.0001 it is!admin wrote:Not sure if I find the time to add it to scripting before 13.00.
-
- Posts: 855
- Joined: 05 Oct 2011 13:15
Re: If (Var == "value1|value2|value3")
@TheQwerty
Thanks for clarifying your idea! I've had this need a few times too, so a GetTokenIndex would surely be a nice addition (when it comes)!
Thanks for clarifying your idea! I've had this need a few times too, so a GetTokenIndex would surely be a nice addition (when it comes)!
• Scripts: Session Manager | SlideShow | Collection Manager | Power Launcher | Akelpad syntax highlighting | ...
-
- Site Admin
- Posts: 60635
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: If (Var == "value1|value2|value3")
No, it was v13.00.0003.TheQwerty wrote:13.00.0001 it is!admin wrote:Not sure if I find the time to add it to scripting before 13.00.
FAQ | XY News RSS | XY Twitter