Filter question, mismatched returns (solved)

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
monki
Posts: 59
Joined: Tue Dec 13, 2011 10:56 pm

Filter question, mismatched returns (solved)

Post by monki » Thu Oct 08, 2015 3:53 am

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.
Last edited by monki on Thu Oct 08, 2015 9:04 pm, edited 1 time in total.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Filter question

Post by dunbarx » Thu Oct 08, 2015 4:32 am

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

monki
Posts: 59
Joined: Tue Dec 13, 2011 10:56 pm

Re: Filter question, mismatched returns (solved)

Post by monki » Thu Oct 08, 2015 5:18 pm

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

Post Reply