Page 1 of 1

Filter question, mismatched returns (solved)

Posted: Thu Oct 08, 2015 3:53 am
by monki
I'm using "filter" for the first time on a project and I'm wondering why the version with the wildcard returns the proper filtered list, but more than I really need (because of the wildcard)...

Code: Select all

filter sSearchText with (aWord & "*") into tFilteredLines 
...and the version with just the word I'm looking for returns nothing, even though the matching item is there.

Code: Select all

filter sSearchText with aWord into tFilteredLines 
The function's using the first item to filter out a line from a variable so a following command can return the second line item:

Code: Select all

aa,can
ab,about
af,after
ag,again
agt,against
The wildcard version will return (af,after) for (af*). The non-wildcard version will return nothing. I'm just wondering why that is happening so I can get a better idea of how "filter" works. Thanks.

Re: Filter question

Posted: Thu Oct 08, 2015 4:32 am
by dunbarx
Hi.

The filter command, just like the "matchText" function, requires practice.

The wildcard "*" (default is "lines") returns "af,after" because all chars are acceptable after the string "af" within a line. Note you cannot specify "items", since any arbitrary item in that list, except for the first one, will return text on two lines. Try it:

Code: Select all

filter items of sSearchText with "about" & return &  "af" into tFilteredLines
The filter with only the string "af" will not return anything because the line containing it is not merely "af", but much more.
Try adding "af" alone to the bottom of the list, and it will indeed appear.

Oh, did I mention this command needs practice?

Craig Newman

Re: Filter question, mismatched returns (solved)

Posted: Thu Oct 08, 2015 5:18 pm
by monki
Ah, that would explain it. Now I have a better understanding of how, and when, to use a filter.

It also solved my issue with the code returning a mismatch. I just added a comma before the wildcard

Code: Select all

filter sSearchText with (sWord & ",*") into tFilteredLines
That will return "anr,answer" for "anr,*", but will return nothing for "an,*". Just as it should
Thanks