Page 1 of 1

Use the Filter command like a pro

Posted: Tue Jun 22, 2021 2:34 pm
by dunbarx
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