Question regarding CR LF and CRLF
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Question regarding CR LF and CRLF
Hi again,
Sorry for pestering everyone with my questions, I am new to coding all together so this is a very steep curve I am on.
I have a question about Line Feeds... I think???
I have a Text field (one piece of Data per line) that I am writing to a simple text file in the Documents Directory on the IOS platform (iPad).
I am then sending this file via FTP to a windows (for now) host computer to process. Plan to send to both Mac and Windows in the future..
When i look at the file on my Mac it appears correct but on windows is not understanding the Line Feeds.
Is there a way I can write the Line Feeds into this file to be understood by both Windows and MAC? Do I need to code into the text file create CRLF and if so
any examples would be great...
Thanks in advanced..
Kia
Sorry for pestering everyone with my questions, I am new to coding all together so this is a very steep curve I am on.
I have a question about Line Feeds... I think???
I have a Text field (one piece of Data per line) that I am writing to a simple text file in the Documents Directory on the IOS platform (iPad).
I am then sending this file via FTP to a windows (for now) host computer to process. Plan to send to both Mac and Windows in the future..
When i look at the file on my Mac it appears correct but on windows is not understanding the Line Feeds.
Is there a way I can write the Line Feeds into this file to be understood by both Windows and MAC? Do I need to code into the text file create CRLF and if so
any examples would be great...
Thanks in advanced..
Kia
Re: Question regarding CR LF and CRLF
Hi Kia,
Yes, to make your file wrap correctly on Windows, you need to use crlf. By default, LiveCode writes files that use the line endings appropriate for the current platform.
To create a Windows compatible text file on Mac OS X, create data with crlf line endings and use binfile or open for binary write to save your file:
or
Kind regards,
Mark
Yes, to make your file wrap correctly on Windows, you need to use crlf. By default, LiveCode writes files that use the line endings appropriate for the current platform.
To create a Windows compatible text file on Mac OS X, create data with crlf line endings and use binfile or open for binary write to save your file:
Code: Select all
open file myFile for binary write
write myData to file myFile
close file myFile
Code: Select all
put myData into url ("binfile:") & myFile
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Re: Question regarding CR LF and CRLF
Okay so further questions,
currently to write my file currently i am just putting field "Whatever" into URL ("file:file.ext")
to send just using put command to transfer the file (via FTP)
so how do I include the CRLF line endings and I am just best doing this when I send to the windows host as my IOS App is constantly reading and writing to
this file so I need to keep the source file in the current format...
currently to write my file currently i am just putting field "Whatever" into URL ("file:file.ext")
to send just using put command to transfer the file (via FTP)
so how do I include the CRLF line endings and I am just best doing this when I send to the windows host as my IOS App is constantly reading and writing to
this file so I need to keep the source file in the current format...
Re: Question regarding CR LF and CRLF
Hi Nakia,
That's really simple:
Don't forget to use binfile instead of file.
Best,
Mark
That's really simple:
Code: Select all
put fld x into myData
replace cr with crlf in myData
Best,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Re: Question regarding CR LF and CRLF
Okay thanks heaps.
Will this however render the file in a format the IOS App will need to be adapted to read?
Will this however render the file in a format the IOS App will need to be adapted to read?
Re: Question regarding CR LF and CRLF
Or am I better doing something like this.. This way I am just modifying the data on send???
On sendData
Put URL ("file.ext") into tMyData
replace CR with CRLF in tMyData
Put tMyData into URL "FTP://user:pass@destination/folder/file.ext"
End sendData
Where would I declare binfile?
On sendData
Put URL ("file.ext") into tMyData
replace CR with CRLF in tMyData
Put tMyData into URL "FTP://user:pass@destination/folder/file.ext"
End sendData
Where would I declare binfile?
Re: Question regarding CR LF and CRLF
I don't think you can create a text file that's universally compatible. Many text editors will do their best to present a text file to you in the way you (or your end user) is accustomed to seeing it, but to be safe you'd create one format with cr line endings and a separate one for Windows, the way you're doing in your sendData handler.
...and note that this will create a Windows version of the text file, so you may want to come up with a different name from the Mac version, i.e., ftp both files onto the ftp server, one for Windows users and one for mac/ios users. Yes - it's a pain.
Where would I declare binfile?
Code: Select all
Put URL ("file:file.ext") into tMyData
Re: Question regarding CR LF and CRLF
Hi Kia,
You said you wanted to save the file in your documentst directory first. For that, you need to use binfile as I explained in my examples.
If you want to use FTP, you can upload the data using FTP as you do in your script. I'm not sure that the file path in URL ("file.ext") would be correct and you need to add "binfile:" in front of it, just like in my examples.
You don't need to use binfile in the FTP address (just in case you might thinking you do).
You should replace cr with crlf only once. After saving the file, you don't need to replace cr again, when you are going to send the data from the file.
If you are going to read the file with another iOS device, it would be best to replace crlf with cr before putting the data into a field.
Kind regards,
Mark
You said you wanted to save the file in your documentst directory first. For that, you need to use binfile as I explained in my examples.
If you want to use FTP, you can upload the data using FTP as you do in your script. I'm not sure that the file path in URL ("file.ext") would be correct and you need to add "binfile:" in front of it, just like in my examples.
You don't need to use binfile in the FTP address (just in case you might thinking you do).
You should replace cr with crlf only once. After saving the file, you don't need to replace cr again, when you are going to send the data from the file.
If you are going to read the file with another iOS device, it would be best to replace crlf with cr before putting the data into a field.
Kind regards,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Re: Question regarding CR LF and CRLF
Thank mark all worked a treat