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
-
richmond62
- Livecode Opensource Backer

- Posts: 10099
- Joined: Fri Feb 19, 2010 10:17 am
Post
by richmond62 » Thu Jun 10, 2021 9:09 am
This is carried over from the Use-List . . .
I want to replace all text within in parentheses (including the parentheses) with a single space. I have tried assembling the matchExpression in advance and in line, and also escaping the parentheses just in case they are reserved in regex. Or do I need to enclose the matchExpression in something other than or in addition to, quotes?
I did things another way:
Code: Select all
on mouseUp
put empty into fld "f2"
put fld "fff" into FLUFFY
put 0 into CHEK
repeat until FLUFFY is empty
put char 1 of FLUFFY into FUR
delete char 1 of FLUFFY
switch FUR
case "("
put 1 into CHEK
break
case ")"
put 0 into CHEK
break
default
if CHEK < 1 then
put FUR after fld "f2"
else
--- do nix
end if
end switch
end repeat
end mouseUp
-
-
Attachments
-
- DeParenthesizer.livecode.zip
- Here's the stack.
- (2.35 KiB) Downloaded 297 times
-
richmond62
- Livecode Opensource Backer

- Posts: 10099
- Joined: Fri Feb 19, 2010 10:17 am
Post
by richmond62 » Thu Jun 10, 2021 9:10 am
Um: forgot to put a SPACE in, just deleted everything . . .
-
jsburnett
- VIP Livecode Opensource Backer

- Posts: 121
- Joined: Fri Mar 09, 2007 9:47 pm
Post
by jsburnett » Fri Jun 11, 2021 5:52 pm
I tried replaceText but could not get that to work.
Try this.
"on mouseUp
put field 1 into tText
repeat with x = the number of chars of tText down to 0
if char x of tText is "(" or char x of tText is ")"
then
delete char x of tText
end if
end repeat
put tText
end mouseUp:
Field 1 is the starting text.
John Burnett
-
jmburnod
- VIP Livecode Opensource Backer

- Posts: 2729
- Joined: Sat Dec 22, 2007 5:35 pm
-
Contact:
Post
by jmburnod » Fri Jun 11, 2021 6:09 pm
Hi Richmond,
Thanks for sharing]
DeParenthesizer works fine here
Best
Jean-Marc
https://alternatic.ch
-
bogs
- Posts: 5480
- Joined: Sat Feb 25, 2017 10:45 pm
Post
by bogs » Fri Jun 11, 2021 9:47 pm
Um, jsburnett, that will certainly take out parenthesis, but that was only part of the equation posted.
first post wrote:
I want to replace all text within in parentheses (including the parentheses) with a single space.
I'm pretty sure you could do this easily with offset (character level to find the parenthesis and set up a marker for each) and replaceText (marker 1 to marker 2) in a fairly small repeat loop.
-
jsburnett
- VIP Livecode Opensource Backer

- Posts: 121
- Joined: Fri Mar 09, 2007 9:47 pm
Post
by jsburnett » Fri Jun 11, 2021 10:12 pm
O. Oops
How about “offset”.
Use offset to find the “(“ the. “)” chars.
Then delete the chars in between.
Repeat this till no pairs remain.
Just an idea off the top of my head.
Or use the other script and keep deleting till the “)” is ‘found’
-
bogs
- Posts: 5480
- Joined: Sat Feb 25, 2017 10:45 pm
Post
by bogs » Fri Jun 11, 2021 11:17 pm
jsburnett wrote: ↑Fri Jun 11, 2021 10:12 pm
How about “offset”.
Use offset to find the “(“ the. “)” chars.
Then delete the chars in between.
Hee hee, I thought I said that
This also apparently works ok...
Code: Select all
on mouseUp
put "" into field 2
put field 1 into theSource
repeat with x=1 to the number of characters of theSource
wait 5 ticks with messages
if character x of theSource is not "(" then
put character x of theSource after field 2
else
put offset(")",theSource) into blipMe
replace character x to blipMe of theSource with " " in theSource
next repeat
end if
end repeat
end mouseUp

-
jsburnett
- VIP Livecode Opensource Backer

- Posts: 121
- Joined: Fri Mar 09, 2007 9:47 pm
Post
by jsburnett » Fri Jun 11, 2021 11:49 pm
Ok, I may not be seeing the entire thread.
out
-
AxWald
- Posts: 578
- Joined: Thu Mar 06, 2014 2:57 pm
Post
by AxWald » Sat Jun 12, 2021 8:22 am
Hi,
Code: Select all
on mouseUp
get fld "f1_fld"
put false into mySkip
repeat for each char C in it
if C = "(" then
put true into mySkip
put space after myRes -- the "single space"
else if C = ")" then
put false into mySkip
else if not mySkip then
put C after myRes
end if
end repeat
replace " " with " " in myRes -- optional, restores it to a nice text
put myRes into fld "f2_fld"
end mouseUp
;-)
Have fun!
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!
-
dunbarx
- VIP Livecode Opensource Backer

- Posts: 10317
- Joined: Wed May 06, 2009 2:28 pm
Post
by dunbarx » Sat Jun 12, 2021 6:21 pm
So why does this not work:
Code: Select all
filter textWithParens without "(*)"
Craig
-
stam
- Posts: 3072
- Joined: Sun Jun 04, 2006 9:39 pm
Post
by stam » Sat Jun 12, 2021 6:36 pm
Or just use regex.
There was a discussion. It so long ago here:
viewtopic.php?f=7&t=35679
The discussion was on how to find text between 2 delimiters. Regex works very well for this and is less code…
-
richmond62
- Livecode Opensource Backer

- Posts: 10099
- Joined: Fri Feb 19, 2010 10:17 am
Post
by richmond62 » Sat Jun 12, 2021 7:19 pm
Why does
regex get on my nerves?
Possibly because I have a "thing" about doing everything inwith LiveCode as such.
Or, just possibly because it does NOT look like LiveCode, but much more like the type of computer languages I almost
completely turned my back on in 1993 (When I discovered HyperCard):
-
-
jacque
- VIP Livecode Opensource Backer

- Posts: 7391
- Joined: Sat Apr 08, 2006 8:31 pm
-
Contact:
Post
by jacque » Sat Jun 12, 2021 9:00 pm
Code: Select all
put replacetext(fld 1,"\(.*?\)",space) into tNewText
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
-
bogs
- Posts: 5480
- Joined: Sat Feb 25, 2017 10:45 pm
Post
by bogs » Sat Jun 12, 2021 9:25 pm
I dunno why regex gets on your nerves Richmond, it is no more or less than a few plain english symbols and the command as Jacque put it is certainly shorter than anything else that popped in so far. Orders of magnitude faster as well I wager.
I keep meaning to get around to parsing it, but usually in the time it would take me to doing that, I've already figured out a (short enough) brute force method

Last edited by
bogs on Sat Jun 12, 2021 9:27 pm, edited 1 time in total.
-
richmond62
- Livecode Opensource Backer

- Posts: 10099
- Joined: Fri Feb 19, 2010 10:17 am
Post
by richmond62 » 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.)