Problem to split string with CR \n character

509 views
Skip to first unread message

Jemand der GerneAnonymBleibt

unread,
Mar 22, 2016, 12:22:49 PM3/22/16
to mitappinv...@googlegroups.com

I have a string which I want to split at the CRs. I know there are CRs (\r, ASCII: 13/0x0D). If I convert the string to URI I see it:




xxxx%0Dyyyyy%0Dzzz...

If I test what code is generated if I convert a "\n"



I receive correct "%0A"


But if I convert "\r" I receive "%5Cr"



The result is that I can not split the string with any way:




What can I do?


My way to convert it with web.uriencode is not the solution because there is no UriDecode-function.

Abraham Getzler

unread,
Mar 22, 2016, 1:31:45 PM3/22/16
to MIT App Inventor Forum
See your other thread, where I gave you hexify().
ABG

Jemand der GerneAnonymBleibt

unread,
Mar 22, 2016, 4:05:55 PM3/22/16
to mitappinv...@googlegroups.com
Sorry but what this should help? I did not need a HTML-Coded special char.

Abraham Getzler

unread,
Mar 22, 2016, 6:24:36 PM3/22/16
to MIT App Inventor Forum
If you assign hexify("0D") to a global, named for example CR, you could then
code replace all text (incoming_text, CR, "")

ABG

Abraham Getzler

unread,
Mar 22, 2016, 6:25:40 PM3/22/16
to MIT App Inventor Forum
Or you could code split at (incoming text, CR)
ABG

Jemand der GerneAnonymBleibt

unread,
Mar 23, 2016, 5:25:39 AM3/23/16
to MIT App Inventor Forum

I think you did not understand the problem or did not try out your code. :-/


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------


But I find out a working way. Maybe other users can use it and it is helpfull:



Taifun

unread,
Mar 23, 2016, 10:20:37 AM3/23/16
to MIT App Inventor Forum
I think you did not understand the problem or did not try out your code. :-/
???

this is ABG's suggestion to convert CR to LF (slightly simplified)


and it looks somehow easier, what do you think?
Taifun

Trying to push the limits of App Inventor! Snippets, Tutorials and Extensions from Pura Vida Apps by Taifun. 

Jemand der GerneAnonymBleibt

unread,
Mar 23, 2016, 1:18:17 PM3/23/16
to mitappinv...@googlegroups.com
No. As I say: I think you did not test it or did not understand the problem/question.

Taifun

unread,
Mar 23, 2016, 1:47:56 PM3/23/16
to MIT App Inventor Forum
correct, I did not test it, unfortunately I do not have a test file
in case you are interested in a simpler solution, you might want to provide a test file somewhere in the internet, so I can download that file using the web component and test
thank you
Taifun

Taifun

unread,
Mar 23, 2016, 3:36:07 PM3/23/16
to mitappinv...@googlegroups.com
I found a test file meanwhile here https://groups.google.com/d/msg/mitappinventortest/IJI2lUqWtBI/tWCw29AadKAJ
it seems to be, your conversion is the way to go currently
Taifun

Abraham Getzler

unread,
Mar 23, 2016, 3:41:05 PM3/23/16
to MIT App Inventor Forum
I tested a small Notepad file, and got a couple of surprises ...

The file had CRLF line endings on Windows, but uploading it into the Media folder and opening it in Ai2 showed only LF line endings.
(I have seen FTP do this type of conversion across architectures.)  The string length of 6 is proof that 3 CRs were lost.

The second surprise was when I tried to convert 0D0A all at once using hexify().  I got a wierd 1 chraacter squiggle.

Doing the conversions 1 byte at a time and joining them seems better.

See attached.

ABG


CRLF_length.png
hexify.aia
hexify.png
hexify_0A.png
hexify_0D.png
hexify_0D0A.png
LF.png
STRIP_CRLF.png
STRIP_LF.png
test_output.png
testfile_NotepadPlusPlus.png
blocks.png
BOM.png
CR.png
CRLF.png
Reply all
Reply to author
Forward
Message has been deleted
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages