Carriage Return
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Carriage Return
Dear fellow LiveCode users,
Just to help prevent some of you getting a bit confused as I have, please note that at the time of my writing this post, the word "CR" in LiveCode does NOT mean control character 13. Even though CR is supposed to mean "Carriage Return", the LiveCode engine has CR meaning the same thing as LF (Line-feed), which is control character 10. Keeping this in mind may save you some headaches when working with text data.
Gerrie
Just to help prevent some of you getting a bit confused as I have, please note that at the time of my writing this post, the word "CR" in LiveCode does NOT mean control character 13. Even though CR is supposed to mean "Carriage Return", the LiveCode engine has CR meaning the same thing as LF (Line-feed), which is control character 10. Keeping this in mind may save you some headaches when working with text data.
Gerrie
-
- Livecode Opensource Backer
- Posts: 9404
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Carriage Return
I must be very stupid, but as far as I can see the effect of CR or LF in a textField is identical.
Re: Carriage Return
Their effect is identical precisely because CR and LF in LiveCode have been defined as control character 10, even though they were supposed to be different.
-
- Livecode Opensource Backer
- Posts: 9404
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Carriage Return
Oddly enough CR and LF seem to have been conflated:
- -
Yet it is perfectly possible to do this:
or this:
but a quick-n-dirty codePointToNum for both those does return 10.
If you do this sort of thing:
the result looks like SPACE + 'x'.
I would suppose the reason for CRLF is to keep Windows users happy:
- -
https://stackoverflow.com/questions/155 ... reak-types
- -
Yet it is perfectly possible to do this:
Code: Select all
on mouseUp
put (CR & "x") after fld "ff"
end mouseUp
Code: Select all
on mouseUp
put (LF & "q") after fld "ff"
end mouseUp
If you do this sort of thing:
Code: Select all
on mouseUp
put empty into fld "ff"
put ((numToCodePoint(13)) & "x") after fld "ff"
end mouseUp
I would suppose the reason for CRLF is to keep Windows users happy:
- -
https://stackoverflow.com/questions/155 ... reak-types
-
- Livecode Opensource Backer
- Posts: 9404
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Carriage Return
I'm not sure that is the strict definition of what is going on, although on the surface it appears that way.
LiveCode will work internally with line endings as char(10) but for cross-platform purposes, will adjust any text output (ie not binfile:) to use the standard as applied on the platform in use.
So if you
Code: Select all
put "line 1" & cr & "line 2" into tText
put tText into url ("file:" & specialFolderPath("documents") & "/test.txt"
Re: Carriage Return
If the standard newline char is giving you issues:
Since the regex \R token (capital R) will find all possible variations of a line ending, you could simply run
to clean up any imported data and/or export data in appropriate format...
Since the regex \R token (capital R) will find all possible variations of a line ending, you could simply run
Code: Select all
replaceText (<container>, "\R", "<my newLine ascii char of choice>")
Re: Carriage Return
Very correct. Internally, RETURN, LINEFEED, LF, and CR are synonyms that all evaluate to ASCII 10. It does not really matter when within LiveCode though (text in fields). When you import text into LC, the line delimiter is changed to 10 and that is what LC uses. When you save text, the value is changed depending on platform. For Linux you get 10, for Windows you get 13+10, for Mac you get 13 (but should change to 10 in the v10 update cycle).
If you are processing text files and the source line ending is important to retain, then you need to open them as binary and store in variables (also need to handle UTF decoding with textDecode)
If you are processing text files and the source line ending is important to retain, then you need to open them as binary and store in variables (also need to handle UTF decoding with textDecode)
Brian Milby
Script Tracker https://github.com/bwmilby/scriptTracker
Script Tracker https://github.com/bwmilby/scriptTracker
-
- VIP Livecode Opensource Backer
- Posts: 9844
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Carriage Return
The CR constant has been such a common FAQ some years ago I wrote about on LiveCode Journal, with background on how it got that way and tips for working with it:
http://livecodejournal.com/features/liv ... dings.html
http://livecodejournal.com/features/liv ... dings.html
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Carriage Return
Thanks for the URL Richard - a good read indeed.FourthWorld wrote: ↑Wed Apr 19, 2023 10:37 pmThe CR constant has been such a common FAQ some years ago I wrote about on LiveCode Journal, with background on how it got that way and tips for working with it:
http://livecodejournal.com/features/liv ... dings.html
More importantly I had never come across LiveCode Journal before, in spite quite a bit of Googling for LiveCode resources, I’ll definitely spend some time delving in it.
There seem to be many resources that appear abandoned and much of the useful stuff that may still valid just doesn’t seem accessible, which is a loss…