Deleting carriage returns

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
Livecode Opensource Backer
Posts: 10098
Joined: Fri Feb 19, 2010 10:17 am

Deleting carriage returns

Post by richmond62 » Sat Dec 31, 2022 2:13 pm

I have a field that looks like this:
-
SShot 2022-12-31 at 15.12.43.png
SShot 2022-12-31 at 15.12.43.png (3.77 KiB) Viewed 5981 times
-
where I hit the ENTER key every line before the 'r', and wonder why this does NOT work:

Code: Select all

on mouseUp
   if line 1 of fld "ff" contains cr then
      delete line 1 of fld "ff"
   end if
end mouseUp

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10098
Joined: Fri Feb 19, 2010 10:17 am

Re: Deleting carriage returns

Post by richmond62 » Sat Dec 31, 2022 2:47 pm

No dice either:

Code: Select all

on mouseUp
   if line 1 of fld "ff" contains linefeed then
      delete line 1 of fld "ff"
   end if
end mouseUp

SparkOut
Posts: 2945
Joined: Sun Sep 23, 2007 4:58 pm

Re: Deleting carriage returns

Post by SparkOut » Sat Dec 31, 2022 3:35 pm

If that were going to work, then it would also delete a line containing any text, so probably not what you're after?
But if you are trying to filter field "ff" not to have any empty lines, you can

Code: Select all

filter field "ff" without empty
In answer to the "why" of your other code not deleting lines, I think it is to do with the interpretation of the cr as being either "part of" the line or "a delimiter".

Code: Select all

put line 1 of field "ff" contains cr 
I expect to return false, as "line 1" is empty - the cr doesn't comprise any line "content".

Jacque will probably remember some in depth debate with more/better info.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7391
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Deleting carriage returns

Post by jacque » Sat Dec 31, 2022 5:49 pm

I think you did a great job explaining it. I do remember several discussions about line delimiters but I can't remember where they are now.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

SparkOut
Posts: 2945
Joined: Sun Sep 23, 2007 4:58 pm

Re: Deleting carriage returns

Post by SparkOut » Sat Dec 31, 2022 6:56 pm

I was thinking you might have some anecdote of a discussion taking place while you and Mark Waddingham broke into Dr Raney's apartment and wallpapered his bedroom with omelettes or something.

But yeah, I think something about how the delimiters are treated as "belonging to" the line but not contributing any content.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7391
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Deleting carriage returns

Post by jacque » Sat Dec 31, 2022 7:46 pm

That would have to have been Heather. She keeps chickens. 😊

Anecdote: My husband Jack and I visited Wales a few years ago and Heather had us and a few team members over to visit. She showed me her garden and her chicken coop because she knew I loved birds. I didn't know you could cuddle a chicken. She put one in my arms and it let me stroke it, it was quite content. When we came back into the house I said, "Oh wow, I want one!" and the whole room exploded in laughter. Apparently while we were out there, Jack said, "great, now she's going to want one."

He knows me too well.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

SparkOut
Posts: 2945
Joined: Sun Sep 23, 2007 4:58 pm

Re: Deleting carriage returns

Post by SparkOut » Sat Dec 31, 2022 9:43 pm

Mmmm, I can believe Heather might supply the ingredients for the omelettes, but I can't imagine her breaking in to wallpaper his apartment. She'd have baked him a cake maybe. Nice deflection, but you and Mark are still my prime suspects. :wink:

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: Deleting carriage returns

Post by dunbarx » Sun Jan 01, 2023 12:28 am

I understand the point that there is a difference between a cr being a (line) delimiter as opposed to simply being a character. And that this has an effect on chunk values overall.

I have a field of ten lines, with an "X" in line 5. The number of lines is 10. The number of chars is also 10. But line 3, say, is empty, even though it contains one of those ten chars, and of course LC states that

Code: Select all

the number of chars of line 3 of fld 1
is one.

But neither of

Code: Select all

if line 5 of fld 1 = cr then beep 2
if line 5 of fld 1 contains cr then beep 2
beeps.
So cr is indeed a char, and is counted as one, but is neither "seen" nor counted as one by LC at all if another char lives in the line of interest.

Craig

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7391
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Deleting carriage returns

Post by jacque » Sun Jan 01, 2023 1:27 am

SparkOut wrote:
Sat Dec 31, 2022 9:43 pm
Mmmm, I can believe Heather might supply the ingredients for the omelettes, but I can't imagine her breaking in to wallpaper his apartment. She'd have baked him a cake maybe. Nice deflection, but you and Mark are still my prime suspects. :wink:
Well, it was worth a try...

I forgot to mention that the chicken crapped on my hand. It was either very relaxed or passive aggressive.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7391
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Deleting carriage returns

Post by jacque » Sun Jan 01, 2023 1:29 am

dunbarx wrote:
Sun Jan 01, 2023 12:28 am
So cr is indeed a char, and is counted as one, but is neither "seen" nor counted as one by LC at all if another char lives in the line of interest.
It's counted when dealing with strings but not when working with text chunks. It has multiple personalities.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: Deleting carriage returns

Post by mwieder » Sun Jan 01, 2023 5:30 am

Wow. A single thread with crapping chickens, omelette wallpaper, and multiple personalities.
Welcome to 2023.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10098
Joined: Fri Feb 19, 2010 10:17 am

Re: Deleting carriage returns

Post by richmond62 » Sun Jan 01, 2023 11:21 am

Of course there are several ways to make an omelette:

https://thehiddenveggies.com/chickpea-o ... -omelette/

This one avoids any problems as to linefeed, carriage return, or what-have-ye altogether:

Code: Select all

on mouseUp
      put the number of words in fld "ff" into WN
      put the word 1 to WN of fld "ff" into EFF
      put empty into fld "ff"
      put EFF into fld "ff"
      select after fld "ff"
   end mouseUp

SparkOut
Posts: 2945
Joined: Sun Sep 23, 2007 4:58 pm

Re: Deleting carriage returns

Post by SparkOut » Mon Jan 02, 2023 5:17 pm

I see you were wanting to strip extraneous CRs from the beginning and end of a tract of text.
The "filter" option would strip empty lines from the middle as well.
Yet, "empty" is still your friend - you don't need to check for CR or line endings, just whether the line is empty:

Code: Select all

on mouseUp
   put trimCRs(field "ff") into field "ff"
end mouseUp

function trimCRs pText
   repeat while line 1 of pText is empty
      delete line 1 of pText
   end repeat
   repeat while the last line of pText is empty
      delete the last line of pText
   end repeat
   return pText
end trimCRs

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7391
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Deleting carriage returns

Post by jacque » Mon Jan 02, 2023 7:16 pm

Or shorter:

Code: Select all

put word 1 to -1 of fld "ff" into fld "ff" 
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

SparkOut
Posts: 2945
Joined: Sun Sep 23, 2007 4:58 pm

Re: Deleting carriage returns

Post by SparkOut » Mon Jan 02, 2023 10:16 pm

But but but... that's just... um... efficient rendition of the code task. Like some weirdo.

Post Reply