Replace text of any characters between parentheses with a space

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

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

Re: Replace text of any characters between parentheses with a space

Post by bogs »

richmond62 wrote: Sat Jun 12, 2021 9:26 pm OK: pause for 'evil' Richmond question:
<Pauses...> did you try running it? Hee hee.
Image
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10415
Joined: Fri Feb 19, 2010 10:17 am

Re: Replace text of any characters between parentheses with a space

Post by richmond62 »

"Not tonight, Josephine."

Currently up to my eyeballs in writing a set of rules for a sequence of 18 inter-related
abstract table games that I am in the middle of negotiating a contract about with a
games manufacturing company.
-
Diagonal_Move.png
-
I wonder if anyone LIKES lawyers?
jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7423
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Replace text of any characters between parentheses with a space

Post by jacque »

richmond62 wrote: Sat Jun 12, 2021 9:26 pm
Replace text of any characters between parentheses with a space
OK: pause for 'evil' Richmond question:

Is that to be interpreted that EACH character between parentheses MUST be REPLACED with a SPACE?
(= as many SPACES as their are characters between parentheses.)

Or

that ALL characters between parentheses MUST be REPLACED with a SPACE?
(=1 SPACE regardless of length of string between parentheses.)
In the original list post the goal was to remove everything between parentheses as well as the parentheses themselves, and replace the whole thing with a single space.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10415
Joined: Fri Feb 19, 2010 10:17 am

Re: Replace text of any characters between parentheses with a space

Post by richmond62 »

Thanks for the clarification. :)
FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10103
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Replace text of any characters between parentheses with a space

Post by FourthWorld »

richmond62 wrote: Sat Jun 12, 2021 9:32 pm Currently up to my eyeballs in writing a set of rules for a sequence of 18 inter-related
abstract table games that I am in the middle of negotiating a contract about with a
games manufacturing company.
Please keep us posted when it launches.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: Replace text of any characters between parentheses with a space

Post by bogs »

This is pretty late in coming, I had originally sent it as a pm but just found out it was never opened.
jsburnett wrote: Fri Jun 11, 2021 11:49 pm Ok, I may not be seeing the entire thread.
out
Hey man, I was only kidding around, sorry if I offended you somehow, but I never meant for you to quit the thread :(

Again, my humblest apologies.
Image
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10501
Joined: Wed May 06, 2009 2:28 pm

Re: Replace text of any characters between parentheses with a space

Post by dunbarx »

Mentioned this earlier. Still wondering why this does not work:

Code: Select all

  filter yourText without "(" &  "*" & ")" 
I have used the "filter" command here and there for ages, but seem to have forgotten how it works.

Craig
stam
Posts: 3209
Joined: Sun Jun 04, 2006 9:39 pm

Re: Replace text of any characters between parentheses with a space

Post by stam »

dunbarx wrote: Mon Jun 21, 2021 9:23 pm Mentioned this earlier. Still wondering why this does not work:

Code: Select all

  filter yourText without "(" &  "*" & ")" 
I have used the "filter" command here and there for ages, but seem to have forgotten how it works.

Craig
Hi Craig - it kinda works... if you have a line that starts and ends with a parenthesis, it will remove that line. But it does not remove this from part of a line... The dictionary definition of filter suggests you can't filter chars, only lines from a text container:

Code: Select all

filter [{lines | items | keys | elements} of] <filterSource>... 
Jacque's suggestion works best and replaces fragments of text anywhere in the container...:
jacque wrote: Sat Jun 12, 2021 9:00 pm

Code: Select all

put replacetext(fld 1,"\(.*?\)",space) into tNewText
If you want to stick with filter, i guess you could replace "(" with CR & "(" and ")" with ")" & CR and then run filter, but that seems like a waste of effort... I mean this works, but you'll need at least 2 extra lines:

Code: Select all

replace "(" with CR & "(" in field 1
replace ")" with ")" & CR in field 1
filter field 1 without "(" &  "*" & ")"
Stam
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10501
Joined: Wed May 06, 2009 2:28 pm

Re: Replace text of any characters between parentheses with a space

Post by dunbarx »

Stam.

Thanks for that. Always read the dictionary. Always read the dictionary...

I went over other stacks where I had used "filter", and found that I was never going down to the character level.

Glad that I at least had the right idea. I find filter more accessible than any of the regex-based gadgets, because I can "see" wildcards more easily.

The CR kludge is, for me, actually a nice one. I do this sort of manhandling of a body of text now and then, and see it as perfectly legit: re-format text to comply with the limitations of a command or function, run it, and restore.. In this kludge, restoring means doing something like inserting a little-used character, like "|", and:

Code: Select all

on mouseup
     get fld "x"
     replace "(" with "|" & CR & "(" in it
     replace ")" with ")" & CR in it
     filter it without "(" &  "*" & ")"
     replace "|" & return with "" in it
     put it into fld "x"
   end mouseup
This restores the original text as written. There are better choices for the special character, perhaps numToChar(240)

Craig
Post Reply