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
-
Mariasole
- Posts: 235
- Joined: Tue May 07, 2013 9:38 pm
Post
by Mariasole » Wed Jul 06, 2016 3:19 pm
Dear friends more experienced, I have another question to ask yourself.
I have to give a format to a long string of fairy tales...
My text is so:
Code: Select all
<p>All work and
no play
makes Jack a
dull boy
All work and no play makes
Jack a dull boy
All work and no play makes
Jack a dull boy
</p>
I would replace
returns with
space, from <p> to </p> with "replaceText" and make it so:
Code: Select all
<p>All work and no play makes Jack a dull boy All work and no play makes Jack a dull boy All work and no play makes Jack a dull boy </p>
I tried this solution I found here (
http://stackoverflow.com/questions/1605 ... een-p-tags):
Code: Select all
[\r\n]+(?=(?:[^<]+|<(?!/?p\b))*</p>)
then...
Code: Select all
put replaceText(tFairy,"[\r\n]+(?=(?:[^<]+|<(?!/?p\b))*</p>)"," ") into tFairy
But it does not work!

I think it "regex" and not "PCRE" although I would not say nonsense!
Can you help me?
Thank you so much for the support given to us beginners!
Never lose patience with our stupid demands!
We are learning! Sooner or later we will learn!
And when we are good we will help beginners, based on your generosity and your example!
Thank you all!
Mariasole
(=^..^=)
"I'm back" - The Cyberdyne Systems Model 101 Series 800 Terminator
-
dunbarx
- VIP Livecode Opensource Backer

- Posts: 10330
- Joined: Wed May 06, 2009 2:28 pm
Post
by dunbarx » Wed Jul 06, 2016 3:53 pm
Maria.
Why not simply:
Code: Select all
replace return with space in yourContainer
Craig Newman
-
Mariasole
- Posts: 235
- Joined: Tue May 07, 2013 9:38 pm
Post
by Mariasole » Wed Jul 06, 2016 4:08 pm
Hi Craig!
I wish it were that simple!
Unfortunately my stories are in HTML, and to me it is mainly that between <p> and </p> tags the returns are replaced with a space. Other tags must remain intact with their respective return!
Thank you for your reply!
Mariasole
(=^..^=)
"I'm back" - The Cyberdyne Systems Model 101 Series 800 Terminator
-
[-hh]
- VIP Livecode Opensource Backer

- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
Post
by [-hh] » Wed Jul 06, 2016 5:18 pm
Works with LC 7 and later.
Code: Select all
on mouseUp
put fld "IN" into txt
set linedel to "<p>"
set itemdel to "</p>"
repeat with i=2 to the num of lines of txt
replace cr with space in item 1 of line i of txt
end repeat
put txt into fld "OUT"
end mouseUp
Last edited by
[-hh] on Thu Jul 07, 2016 4:59 pm, edited 1 time in total.
shiftLock happens
-
mwieder
- VIP Livecode Opensource Backer

- Posts: 3581
- Joined: Mon Jan 22, 2007 7:36 am
-
Contact:
Post
by mwieder » Wed Jul 06, 2016 5:48 pm
Herman is much too fast for me. I was still trying to figure out an elegant solution for this.
"...in item 1 of"... brilliant.
-
Mariasole
- Posts: 235
- Joined: Tue May 07, 2013 9:38 pm
Post
by Mariasole » Wed Jul 06, 2016 5:58 pm
Dear [-hh], thanks!
Wow, really an elegant and good solution!
But unfortunately I still working on the 6.7.7 version of LC!
I think that I need a
PCRE regex solution...
put replaceText(tFairy,"
[\r\n]+(?=(?:[^<]+|<(?!/?p\b))*</p>)"," ") into tFairy
Thierry, are you there?
Grazie ancora a tutti...
Mariasole
(=^..^=)
"I'm back" - The Cyberdyne Systems Model 101 Series 800 Terminator
-
[-hh]
- VIP Livecode Opensource Backer

- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
Post
by [-hh] » Wed Jul 06, 2016 6:29 pm
Why use for simple things a regex that nobody than Thierry can really handle?
You may use one-char delimiters with LC 6.
Code: Select all
on mouseUp
put fld "IN" into txt
replace "<p>" with numToChar(1) in txt
replace "</p>" with numToChar(2) in txt
set linedel to numToChar(1)
set itemdel to numToChar(2)
repeat with i=2 to the num of lines of txt
replace cr with space in item 1 of line i of txt --> see ***
end repeat
replace numToChar(1) with "<p>" in txt
replace numToChar(2) with "</p>" in txt
put txt into fld "OUT"
end mouseUp
*** As Craig said:
Code: Select all
replace return with space in yourContainer
We only had to fix the yourContainer

Last edited by
[-hh] on Thu Jul 07, 2016 4:59 pm, edited 2 times in total.
shiftLock happens
-
Mariasole
- Posts: 235
- Joined: Tue May 07, 2013 9:38 pm
Post
by Mariasole » Wed Jul 06, 2016 6:46 pm
Dear [-hh],
thanks to downgrade your solution!
I now will test and let you know!
You're a knight [-hh],
you are saving a damsel!
Mariasole
(=^..^=)
"I'm back" - The Cyberdyne Systems Model 101 Series 800 Terminator
-
[-hh]
- VIP Livecode Opensource Backer

- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
Post
by [-hh] » Wed Jul 06, 2016 6:52 pm
Mariasole,
I don't look at gender. It's just because recently Germany had a bit more luck than Italy with penalties.
Last edited by
[-hh] on Thu Jul 07, 2016 4:59 pm, edited 1 time in total.
shiftLock happens
-
Mariasole
- Posts: 235
- Joined: Tue May 07, 2013 9:38 pm
Post
by Mariasole » Wed Jul 06, 2016 8:19 pm
I did not know that Italy had a football team!

"I'm back" - The Cyberdyne Systems Model 101 Series 800 Terminator
-
Mariasole
- Posts: 235
- Joined: Tue May 07, 2013 9:38 pm
Post
by Mariasole » Thu Jul 07, 2016 2:44 pm
Dear [-hh],
I did the test on your nice solution, but unfortunately I found some problems!
First problem: the script changes the formatting of my html, which instead must remain intact.
original to change:
Code: Select all
<span>this is a span tag</span>
<span>this is another span tag</span>
<p>All work and
no play
makes Jack a
dull boy
All work and no play makes
Jack a dull boy
All work and no play makes
Jack a dull boy
</p>
<span>this is the end span tag</span>
result with your script:
Code: Select all
<span>this is a span tag</span> <span>this is another span tag</span> <p>All work and no play makes Jack a dull boy All work and no play makes Jack a dull boy All work and no play makes Jack a dull boy </p>
<span>this is the end span tag</span>
...then what I would like:
Code: Select all
<span>this is a span tag</span>
<span>this is another span tag</span>
<p>All work and no play makes Jack a dull boy All work and no play makes Jack a dull boy All work and no play makes Jack a dull boy </p>
<span>this is the end span tag</span>
Second problem: When html lines are many, the system is very slow ...
So, probably,
the solution with regex might be the best, just that I have
no idea how to spell !!!
put replaceText(tFairy,"[\r\n]+(?=(?:[^<]+|<(?!/?p\b))*</p>)"," ") into tFairy
????????????
I put an
X on the window and turned on the light, let's see if
PERLman will find a solution ...
Grazie [-hh], grazie a tutti!
Mariasole
(=^..^=)
-
Attachments
-
- NoReturns in P!.zip
- (954 Bytes) Downloaded 186 times
"I'm back" - The Cyberdyne Systems Model 101 Series 800 Terminator
-
FourthWorld
- VIP Livecode Opensource Backer

- Posts: 10052
- Joined: Sat Apr 08, 2006 7:05 am
-
Contact:
Post
by FourthWorld » Thu Jul 07, 2016 3:44 pm
The presence or absence of white space between HTML tags does not affect how it renders. What is the goal of this exercise?
-
[-hh]
- VIP Livecode Opensource Backer

- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
Post
by [-hh] » Thu Jul 07, 2016 5:31 pm
Mariasole,
this was a beginners error (sorry, corrected above):
Of course the repeat should start with i=2, because the first "<p>"-line is *before* the first "<p>".
Hope it works now as you wish.
Here is moreover a faster solution if your input is large, use with LC 6.
Needs here (2.5 GHz Mac mini) < 500 ms for 2 MByte of input.
Code: Select all
--- For LC 6 (easier but slower with LC 7/8)
on mouseUp
lock screen; lock messages
put the millisecs into m1
put fld "IN" into txt; put the num of lines of txt into n1
put numToChar(1) into c1
put numToChar(2) into c2
replace "<p>" with c1 in txt
replace "</p>" with c2 in txt
set linedel to c1; set itemdel to c2
put line 1 of txt into txt2 --> we start AFTER first "<p>"
repeat for each line L in (line 2 to -1 of txt)
replace cr with space in item 1 of L
replace c2 with "</p>" in L
put "<p>" & L after txt2
end repeat
put txt2 into fld "OUT"
set linedel to cr
put length(txt2) & " / replaced " & (n1-the num of lines of txt2) & \
" / " & (the millisecs - m1) & " ms" into fld "timing"
unlock screen; unlock messages
end mouseUp
shiftLock happens
-
Mariasole
- Posts: 235
- Joined: Tue May 07, 2013 9:38 pm
Post
by Mariasole » Fri Jul 08, 2016 11:18 am
FourthWorld wrote:The presence or absence of white space between HTML tags does not affect how it renders. What is the goal of this exercise?
Hi Richard!
It is not a Feng Shui test code

, but rather for the readability of the code. I know it sounds strange, but for my "biggest experiment"

, that of fables that I mentioned a while ago, I want to keep the readability of sources in html!
Grazie!
!(=^..^=)!
"I'm back" - The Cyberdyne Systems Model 101 Series 800 Terminator
-
Mariasole
- Posts: 235
- Joined: Tue May 07, 2013 9:38 pm
Post
by Mariasole » Fri Jul 08, 2016 11:23 am
Grazie [-hh]!
the new code works perfectly and is very fast! I do not understand the differences with LC7 and LC8

, but maybe I will understand when I pass to new versions.
For now 6.x is hard enough for me! Thank you so very much for giving me the solution, and for showing me the very elegant code that I can study and imitate!
I will continue to test the code, and if you had something wrong I'll let you know.
Thanks again!
Mariasole
(=^..^=)
"I'm back" - The Cyberdyne Systems Model 101 Series 800 Terminator