Saving To Text File - Android
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Saving To Text File - Android
Hello Guys!
A little problem Im having...
on inputReturnKey
put mobilecontrolget("emailtext","text") into tEmailText
put tEmailText after URL "file:/mnt/sdcard/email.txt"
mobileControlSet "emailText", "text", ""
end inputReturnKey
When it saves tEmailText to /mnt/sdcard/email.txt I get spaces between the items, for example,
Test1
Test2
Test3
Test4
and im trying to get,
Test1
Test2
Test3
Test4
Any suggestions?
Many Thanks,
Matthew.
A little problem Im having...
on inputReturnKey
put mobilecontrolget("emailtext","text") into tEmailText
put tEmailText after URL "file:/mnt/sdcard/email.txt"
mobileControlSet "emailText", "text", ""
end inputReturnKey
When it saves tEmailText to /mnt/sdcard/email.txt I get spaces between the items, for example,
Test1
Test2
Test3
Test4
and im trying to get,
Test1
Test2
Test3
Test4
Any suggestions?
Many Thanks,
Matthew.
Re: Saving To Text File - Android
Hi Matthew,
please only one thread per problem, I deleted the doublette in teh beginner section.
Not sure, I don't develop for Android, but looks like ANDROID is using CRLF as a line delimiter?!
Try this:
...
put mobilecontrolget("emailtext","text") into tEmailText
## Replace with "regular" CR
replace CRLF with CR in tEmailText
## Use BINFILE to preserve the "forced" line delimiter
put tEmailText after URL "binfile:/mnt/sdcard/email.txt"
## Then of course use also BINFILE when reading the file!
...
Not sure it works, but is worth a try
Best
Klaus
please only one thread per problem, I deleted the doublette in teh beginner section.
Not sure, I don't develop for Android, but looks like ANDROID is using CRLF as a line delimiter?!
Try this:
...
put mobilecontrolget("emailtext","text") into tEmailText
## Replace with "regular" CR
replace CRLF with CR in tEmailText
## Use BINFILE to preserve the "forced" line delimiter
put tEmailText after URL "binfile:/mnt/sdcard/email.txt"
## Then of course use also BINFILE when reading the file!
...
Not sure it works, but is worth a try

Best
Klaus
Re: Saving To Text File - Android
Im not sure if im using your information properly Klaus...
Does anyone have any other ideas or explain Klaus' reply a bit more? Sorry to pester...
Many Thanks,
Matthew.
Does anyone have any other ideas or explain Klaus' reply a bit more? Sorry to pester...
Many Thanks,
Matthew.
Re: Saving To Text File - Android
Hi Matthew,
you know that each platform has its own and possibly different text encoding, right?
MacRoman, ISO etc...
e.g. the Mac uses a CR as a line delimiter, but Windows uses CRLF for this.
So if you open a Windows textfile on the Mac you will see empty lines and
strange characters where possible UMLAUTS or accents should be.
I am sure you have experienced this in the past.
Internally Livecode always uses CR as a line delimiter, but when saving to TEXT file
Livecode will automatically replace this with the platform specific LINE DELIMITER character.
Now you can force to keep the internal CR as a linedelimiter, when you use BINFILE
for writing the file. This way LC does NOT use the platform specific line delimiter.
What platform are you using to view these files with empty lines?
Best
Klaus
you know that each platform has its own and possibly different text encoding, right?
MacRoman, ISO etc...
e.g. the Mac uses a CR as a line delimiter, but Windows uses CRLF for this.
So if you open a Windows textfile on the Mac you will see empty lines and
strange characters where possible UMLAUTS or accents should be.
I am sure you have experienced this in the past.
Internally Livecode always uses CR as a line delimiter, but when saving to TEXT file
Livecode will automatically replace this with the platform specific LINE DELIMITER character.
Now you can force to keep the internal CR as a linedelimiter, when you use BINFILE
for writing the file. This way LC does NOT use the platform specific line delimiter.
What platform are you using to view these files with empty lines?
Best
Klaus
Re: Saving To Text File - Android
Hi Klaus,
Im using the file editor in ES File Explorer and says that the file on the Android device is Unicode(UTF-8) .
Does that mean anything to you? There is also ANSI(ASCII) and one selection Western Languages(Windows).
Can you point me in the direction given the information outlined?
Many Thanks,
Matthew.
Im using the file editor in ES File Explorer and says that the file on the Android device is Unicode(UTF-8) .
Does that mean anything to you? There is also ANSI(ASCII) and one selection Western Languages(Windows).
Can you point me in the direction given the information outlined?
Many Thanks,
Matthew.
Re: Saving To Text File - Android
HI Matthew,
I was hoping this would not be neccessary anymore because Livecode stated (with LC version 7.x) "Unicode, it just works!"
Best
Klaus
ao you are using Windows for this?Googie85 wrote:Im using the file editor in ES File Explorer...
Sorry, this encoding stuff is a bit over my head.Googie85 wrote:... and says that the file on the Android device is Unicode(UTF-8) .
Does that mean anything to you? There is also ANSI(ASCII) and one selection Western Languages(Windows).
Can you point me in the direction given the information outlined?
I was hoping this would not be neccessary anymore because Livecode stated (with LC version 7.x) "Unicode, it just works!"

Best
Klaus
Re: Saving To Text File - Android
Did you try?
or
Code: Select all
put mobilecontrolget("emailtext","text") into tEmailText
put tEmailText after URL "binfile:/mnt/sdcard/email.txt"
Code: Select all
put mobilecontrolget("emailtext","text") into tEmailText
put URL "file:/mnt/sdcard/email.txt" into temp
put tEmailText after temp
put temp into URL "file:/mnt/sdcard/email.txt"
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
Re: Saving To Text File - Android
Hello Guys!!
With the above mentioned reply (Thanks A lot) I was wondering if I could encode the text before saving it with function "textEncode". It allows all sorts of formats to be saved. So, with the code above, could someone suggest how to save as a format for Windows? Currently on my Android device it saves .txt files as UTF-8.
Many Thanks,
Matthew.
With the above mentioned reply (Thanks A lot) I was wondering if I could encode the text before saving it with function "textEncode". It allows all sorts of formats to be saved. So, with the code above, could someone suggest how to save as a format for Windows? Currently on my Android device it saves .txt files as UTF-8.
Many Thanks,
Matthew.
Re: Saving To Text File - Android
Windows encoding is CP1252, so use:
Code: Select all
put textencode(mytext,"CP1252")
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
Re: Saving To Text File - Android
Hello Guys,
Ok, Here Goes,
I am finally getting, the results,
Test1
Test2
Test3
Test4
Here is the code,
I am having a little trouble encoding the email.txt file to PC.txt (So that its legible to windows). I've tried encoding it as ASCII and CP1252, this still makes an exact copy of email.txt.
Any Ideas Would Be Awesome,
Many Thanks,
Matthew.
Ok, Here Goes,
I am finally getting, the results,
Test1
Test2
Test3
Test4
Here is the code,
Code: Select all
on inputReturnKey
put mobilecontrolget("emailtext","text") into tEmailText
put URL "binfile:/mnt/sdcard/email.txt" into temp
put return&tEmailText after temp
put temp into URL "binfile:/mnt/sdcard/email.txt"
put URL "binfile:/mnt/sdcard/email.txt" into blahh
put textEncode(blahh,"ASCII") into tempvar
put tempvar into URL "binfile:/mnt/sdcard/PC.txt"
end inputReturnKey
Any Ideas Would Be Awesome,
Many Thanks,
Matthew.
Re: Saving To Text File - Android
What is your problem?
PC.txt look weird on windows? If not, what do you want?
Look this on windows:
Maybe you need this:
using file, instead of binfile, is what you need in this case.
PC.txt look weird on windows? If not, what do you want?
Look this on windows:
Code: Select all
put textEncode("èòàabc","UTF-8") = "èòà abc" #worng char encoding for windows
put textEncode("èòàabc","ASCII") = "???abc" #standard ASCII doesn't support special chars
put textEncode("èòàabc","CP1252") = "èòàabc" #correct char encoding on windows
Code: Select all
put URL "binfile:/mnt/sdcard/email.txt" into blahh
put textEncode(blahh,"ASCII") into tempvar
put tempvar into URL "file:/mnt/sdcard/PC.txt"
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w