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!
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?
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
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:
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.
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
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!
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):
-
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.
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.)