Add new lines to text file and read them

456 views
Skip to first unread message

Medien Forscher

unread,
Sep 9, 2018, 8:20:16 AM9/9/18
to DroidScript
Hi
I can add new lines to text files with +"\n" but when I read the file with var txt = app.ReadFile the line breaks are apparently not read.

When I write it with img.DrawText(txt,0.1, 0.35, "Multiline");

The linebreaks are gone or ignored.
Thx
Olivier

Medien Forscher

unread,
Sep 9, 2018, 8:55:20 AM9/9/18
to DroidScript
Short thing: How can I write \n in a text file that will be read by multiline option?

Steve Garman

unread,
Sep 9, 2018, 11:06:23 AM9/9/18
to DroidScript
\n is the right way to do it.

My guess is you're writing it fine.

Have you tried looking at it in a text editor.

Unless it's something that has been added very recently, img.DrawText does not have a MultiLine option.

GetTextSize was added so you can calculate for yourself where the line breaks and where to start drawing the next line.

Medien Forscher

unread,
Sep 9, 2018, 11:53:06 AM9/9/18
to DroidScript
Thx I managed now to get the \n in my text file (\\n). Now I see something weird. If I take the string text in following code the linebreak works. If I take the string from a textfile the line break doesn't work. Here's the code:

function OnStart() {
lay = app.CreateLayout( "Linear", "VCenter,FillXY" );

//text = "Hello\nWorld";
text = app.ReadFile( "/sdcard/testfile.txt" );
txt = app.CreateText( text, 0.8, 0.2, "Multiline" );
txt.SetTextSize( 12 );
txt.SetTextColor( "#ff6666ff" );
txt.SetBackColor( "#ffffffff" );
lay.AddChild( txt );
app.AddLayout( lay );
}

And here the textfile content:

09/09/2018,57,57,0,0,0,0,00:00:02\n09/09/2018,60,60,0,0,0,0,00:00:01\n

If you put this in a textfile does it break the line with above code?

Steve Garman

unread,
Sep 9, 2018, 12:11:45 PM9/9/18
to DroidScript
Don't double the soashes.

If it looks like
a\nb
in a text editor, it isn't a line break.

In a text editor, a line break should look like
a
b

But that's still not going to help you with your DrawText problem.

Did you read my last pist?

Medien Forscher

unread,
Sep 9, 2018, 3:23:03 PM9/9/18
to DroidScript
Thx very much, that solved the problem. I read it and therefore choose app.CreateText which supports multiline. So now I can show a simple trainig history. Great, thx!
Reply all
Reply to author
Forward
0 new messages