LikeI not working with a # in the comparison string?

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
klownboy
Posts: 4109
Joined: 28 Feb 2012 19:27

LikeI not working with a # in the comparison string?

Post by klownboy »

I was a little surprised today that the following comparison using "LikeI" was not working. The comparison works with "==" but not with LIkeI. The 2 variables are identical (cut and pasted). Am I not supposed to be able to use "LikeI" in a case like this or is it not working properly due to the parenthesis, spaces or # symbol? When I removed the # symbol the LikeI worked. I get the same result if I quote the variables. Potential bug in my brain or in the workings of LikeI? Thanks.

Code: Select all

  $cur_view = Thumbnails #3 (240x240);
  $T_size_sel = Thumbnails #3 (240x240);

  if($T_size_sel LikeI $cur_view) {
    echo "The same";}
  else {
    echo "Not the same";}
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: LikeI not working with a # in the comparison string?

Post by highend »

No bug. LikeI matches pattern
And # is a pattern for a digit

So your comparison checks if
Thumbnails #3 (240x240)
is like
Thumbnails 13 (240x240)
Thumbnails 73 (240x240)
or anything like that

-> No match

This would be a valid comparison

Code: Select all

  $cur_view = "Thumbnails [#]3 (240x240)";
  $T_size_sel = "Thumbnails #3 (240x240)";

  if($T_size_sel LikeI $cur_view) {
    echo "The same";}
  else {
    echo "Not the same";}
One of my scripts helped you out? Please donate via Paypal

klownboy
Posts: 4109
Joined: 28 Feb 2012 19:27

Re: LikeI not working with a # in the comparison string?

Post by klownboy »

OK highend thanks very much. I saw the note on the symbols, but I was not aware that the "#" was a pattern for a digit like ? is for a letter...good to know, should have known. So you bracketed the [#] to treat it as a non-special character on the right side (i.e., pattern side) of the comparison.
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

klownboy
Posts: 4109
Joined: 28 Feb 2012 19:27

Re: LikeI not working with a # in the comparison string?

Post by klownboy »

Since this was on the topic of a "#" symbol but possibly not related. I had the following in a script line that failed

Code: Select all

run "cmd /c <xy> /path=""$cur_folder"" /new /win=tray /script=""::if(!gettokenindex($FVS_view_det, $sel_thumbsize,<crlf>, 'i')){setting 'enablefolderviewsettings',0;}if(replacelist(get('view'), '0|1|2|3|4|5|6|7|8|9', '302|303|304|305|306|307|308|309|313|314','|') != $thumb_cid){#$thumb_cid;wait 50;#1001;}if($match){#501;};wait 50;#1001;if(get('instance')=='2') {exit 'n';}""", , 2, 0;
...everything worked fine 'til I added

Code: Select all

if(!gettokenindex($FVS_view_det, $sel_thumbsize,<crlf>, 'i')){setting 'enablefolderviewsettings',0;}
In stepping though the script that code parses out to be:

Code: Select all

 if(!gettokenindex(Thumbnails #3 (240x240), Thumbnails #3 (240x240)
Thumbnails #1 (128x128)
Thumbnails #2 (240x180),
, 'i')){setting 'enablefolderviewsettings',0;}
I've corrected the issue by obtaining a variable in advance of that gettokenindex value (which I should have done in the first place since it is used a few times), but I was curious if the "#" should be affecting SC gettokenindex? Should I have known that I have to escape the "#" somehow? I say somehow only because it's contained in a variable. The original topic I can understand since it was using LikeI comparisons. Is the "#" considered a wildcard and I should have used the "w" flag? Thanks.
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: LikeI not working with a # in the comparison string?

Post by highend »

Code: Select all

    step;
    text gettokenindex("Thumbnails #1 (128x128)", "Thumbnails #3 (240x240)<crlf>Thumbnails #1 (128x128)<crlf>Thumbnails #2 (240x180)", <crlf>, 'i');
I don't see the issue. You left out the 'w' in the switches parameter -> The token is treated literally
One of my scripts helped you out? Please donate via Paypal

klownboy
Posts: 4109
Joined: 28 Feb 2012 19:27

Re: LikeI not working with a # in the comparison string?

Post by klownboy »

So I think what you're saying is, since I did leave out the "w" switch it should have worked. Like you said, it works as your code line indicates. I tried it again, the script just out and out fails...it went to the 2nd instance but dies with no messages. I have to close the 2nd instance and then the script continues. Unless it has something to do with being run in in a 2nd instance via cmd like it is. Well like I said I've established a variable up front now before the run command so it's working fine.
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

Post Reply