Page 1 of 1
Saving To Text File - Android
Posted: Wed Aug 26, 2015 12:06 pm
by Googie85
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.
Re: Saving To Text File - Android
Posted: Wed Aug 26, 2015 12:21 pm
by Klaus
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
Re: Saving To Text File - Android
Posted: Wed Aug 26, 2015 1:41 pm
by Googie85
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.
Re: Saving To Text File - Android
Posted: Wed Aug 26, 2015 1:55 pm
by Klaus
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
Re: Saving To Text File - Android
Posted: Wed Aug 26, 2015 2:36 pm
by Googie85
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.
Re: Saving To Text File - Android
Posted: Wed Aug 26, 2015 2:39 pm
by Klaus
HI Matthew,
Googie85 wrote:Im using the file editor in ES File Explorer...
ao you are using Windows for this?
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?
Sorry, this encoding stuff is a bit over my head.
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
Posted: Wed Aug 26, 2015 3:55 pm
by MaxV
Did you try?
Code: Select all
put mobilecontrolget("emailtext","text") into tEmailText
put tEmailText after URL "binfile:/mnt/sdcard/email.txt"
or
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"
Re: Saving To Text File - Android
Posted: Thu Aug 27, 2015 9:07 am
by Googie85
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.
Re: Saving To Text File - Android
Posted: Thu Aug 27, 2015 4:36 pm
by MaxV
Windows encoding is
CP1252, so use:
Re: Saving To Text File - Android
Posted: Fri Aug 28, 2015 8:07 am
by Googie85
Hello Guys,
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
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.
Re: Saving To Text File - Android
Posted: Fri Aug 28, 2015 11:41 am
by MaxV
What is your problem?
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
Maybe you need this:
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"
using file, instead of binfile, is what you need in this case.