Filter Script & Patterns & Regex

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Filter Script & Patterns & Regex

Post by dunbarx » Wed Dec 13, 2017 10:01 pm

I am very leery of the "hidden" property. Because hidden lines collapse the other lines, it can be very disconcerting that a field that has five lines only shows three, say. Never mind returns below the field, which are annoying enough.

The hidden property is only useful when actually viewing lines by people with eyes. That is precisely the time that extra care has to be taken so that the number of lines does not conflict with any visual measure, and especially with synchronized scrolling fields.

Craig

chipsm
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 244
Joined: Wed May 11, 2011 7:50 pm
Location: Southern California

Re: Filter Script & Patterns & Regex

Post by chipsm » Wed Dec 13, 2017 10:11 pm

Thanks for the suggestion Jim.
Clarence Martin
chipsm@themartinz.com

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Filter Script & Patterns & Regex

Post by bogs » Wed Dec 13, 2017 10:13 pm

While it is non destructive, Craig rightly points out there are possible 'gotchas' down the line if you need to count the lines. In this example, line 2 is set to 'hidden'.
Image
If you went this route, and later needed to count lines, you'd have to make an allowance for the ones set to hidden, for example (psuedo code)

Code: Select all

// counting the lines
if the hidden of line x is not true then add 1 to myVar
put "the number of lines are " & myVar
Just something to keep in mind.
Image

jiml
Posts: 336
Joined: Sat Dec 09, 2006 1:27 am
Location: Los Angeles

Re: Filter Script & Patterns & Regex

Post by jiml » Thu Dec 14, 2017 1:08 am

Code: Select all

put the number of lines of fld 1
would correctly return 4 in that example, even though line 2 is hidden.

Code: Select all

put line 2 of fld 1
would return:
this is line 2

You are correct that you would need to use a repeat loop and the IF statement you provided in order to count the hidden lines.

It might be nice if these worked:

Code: Select all

put the number of hidden lines of fld 1

Code: Select all

hide line 2 of fld 1
but they don't. :(

If lines 2 and 4 were hidden this would give you a list of the hidden lines - "2,4" :

Code: Select all

function countHidden whatFld
   repeat with x = 1 to the number of lines of fld whatFld
      if the hidden of line x of fld whatFld is true then put x & comma after output
   end repeat
   delete char -1 of output
   return output
end countHidden

Code: Select all

put the number of items of counthidden(1)
gives a count of the hidden lines - 2.

It would be easy to modify the above function to return an array that lists both hidden and shown lines - [hiddenLines[2,4],shownLines[1,3]]

Jim Lambert

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Filter Script & Patterns & Regex

Post by bogs » Thu Dec 14, 2017 2:55 am

I completely agree it is no great chore or difficulty to get the accurate count, as I said, just something to keep in mind if, for instance, it looked like the result you wanted and later couldn't figure out why the field returns 4 lines, and you only see 3.

You wrapped it up nicely in that function, very neat :D
Image

glenn9
Posts: 223
Joined: Wed Jan 15, 2020 10:45 pm
Location: Europe

Re: Filter Script & Patterns & Regex

Post by glenn9 » Tue Apr 14, 2020 10:16 am

dunbarx wrote:
Mon Dec 11, 2017 9:42 pm
I was just trying to be cute with the "don't understand" thing.

That is not to say I understand.

But note that the filter command can be used without all that fancy regex/wildCard stuff. If you have a fid 1 with "a,b,c,d,e,f,g" and you:

Code: Select all

on mouseUp
   filter items of fld 1 without "b" into temp
   answer temp
end mouseUp
you get the string without the "b".

One can move slowly from there, adding filter complexity piece by piece. Use the asterisk wildcard like Klaus mentioned, until you have enough confidence to try your first real regex gadget,

Then check out the "replaceText" function.

Craig
Craig,

I'm trying to engage with filters at the moment and I can't tell you how helpful your post was on being able to implement a filter on an array as part of some learning that I'm undertaking at the moment.

Thanks again,

Kind regards,

Glenn

Post Reply

Return to “Talking LiveCode”