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: 5435
Joined: Sat Feb 25, 2017 10:45 pm

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

Post by bogs » Sat Jun 12, 2021 9:28 pm

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: 9287
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

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

Post by richmond62 » Sat Jun 12, 2021 9:32 pm

"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: 7215
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

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

Post by jacque » Sun Jun 13, 2021 1:22 am

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: 9287
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

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

Post by richmond62 » Sun Jun 13, 2021 1:31 pm

Thanks for the clarification. :)

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9802
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

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

Post by FourthWorld » Tue Jun 15, 2021 4:43 pm

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: 5435
Joined: Sat Feb 25, 2017 10:45 pm

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

Post by bogs » Mon Jun 21, 2021 8:46 pm

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: 9580
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

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

Post by dunbarx » 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

stam
Posts: 2636
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

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

Post by stam » Tue Jun 22, 2021 3:27 am

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: 9580
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

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

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

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

Return to “Getting Started with LiveCode - Complete Beginners”