Use the Filter command like a pro

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

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

Use the Filter command like a pro

Post by dunbarx » Tue Jun 22, 2021 2:34 pm

This derives from another thread:
viewtopic.php?f=7&t=35951

The task was to replace a character string using the "filter" command. This command is not directly applicable at the character level, that is, one cannot, say:

Code: Select all

filter "XYZ" without "Y"
and expect to get "XZ"

But Stam provided a clever kludge, reformatting the string of interest into lines, and filtering that. I added just a little enhancement, to restore the original text. So for example if one wanted to delete, in a body of text, every string enclosed by parens, such as "(abcd)", including the parens themselves:

Code: Select all

on mouseup
   put numToChar(240) into ZZ -- a char unlikely to be found in any text
   get fld 1
   replace "(" with ZZ & CR & "(" in it
   replace ")" with ")" & CR in it
   filter it without "(" &  "*" & ")"
   replace ZZ & return with "" in it
   put it into fld 1
end mouseup
So much fun.

Craig

Post Reply

Return to “Talking LiveCode”