Page 1 of 2

Deleting carriage returns

Posted: Sat Dec 31, 2022 2:13 pm
by richmond62
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 5971 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

Re: Deleting carriage returns

Posted: Sat Dec 31, 2022 2:47 pm
by richmond62
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

Re: Deleting carriage returns

Posted: Sat Dec 31, 2022 3:35 pm
by SparkOut
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.

Re: Deleting carriage returns

Posted: Sat Dec 31, 2022 5:49 pm
by jacque
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.

Re: Deleting carriage returns

Posted: Sat Dec 31, 2022 6:56 pm
by SparkOut
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.

Re: Deleting carriage returns

Posted: Sat Dec 31, 2022 7:46 pm
by jacque
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.

Re: Deleting carriage returns

Posted: Sat Dec 31, 2022 9:43 pm
by SparkOut
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:

Re: Deleting carriage returns

Posted: Sun Jan 01, 2023 12:28 am
by dunbarx
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

Re: Deleting carriage returns

Posted: Sun Jan 01, 2023 1:27 am
by jacque
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.

Re: Deleting carriage returns

Posted: Sun Jan 01, 2023 1:29 am
by jacque
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.

Re: Deleting carriage returns

Posted: Sun Jan 01, 2023 5:30 am
by mwieder
Wow. A single thread with crapping chickens, omelette wallpaper, and multiple personalities.
Welcome to 2023.

Re: Deleting carriage returns

Posted: Sun Jan 01, 2023 11:21 am
by richmond62
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

Re: Deleting carriage returns

Posted: Mon Jan 02, 2023 5:17 pm
by SparkOut
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

Re: Deleting carriage returns

Posted: Mon Jan 02, 2023 7:16 pm
by jacque
Or shorter:

Code: Select all

put word 1 to -1 of fld "ff" into fld "ff" 

Re: Deleting carriage returns

Posted: Mon Jan 02, 2023 10:16 pm
by SparkOut
But but but... that's just... um... efficient rendition of the code task. Like some weirdo.