Pages: [1]   Go Down
Author Topic: new line  (Read 719 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 39
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Im trying to write a String into a file on a SDcard. Each time i write to it it starts on a new line, but i would like to be able to tell when I want a new line to make the data a little bit more readable. Tabs would be nice too.
\n does not work, but it does not show up in the file ider..

any suggestions?
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13739
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
any suggestions?
Post your code so we can see what you tried.
(preferably minimize the sketch that shows this behaviour)

Did you use the somefile.println(); statement? It places a newline in the file.
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Newbie
*
Karma: 0
Posts: 39
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

well, yes and no.

i collect alot of data during some seconds, then put it all with one write to the SDcard to save time(i guess?)

so i have something like this that i want to put into the .txt file and i want it to show the new lines.

String saveThisString="Data:\nvalue1=15\nvalue2=16\nvalue3=4"

with the  somefile.println(); i will get a linefeed only after the howl row is inserted. when i check the textfile i cant see the \n in the file, so the textfile has recogniced them as commands atleast.

i have a computer with swedish on it, if that makes any difference? in old basic you could add a chr(50) to get a linefeed within a text.

I want to save everything to this file as there will be hundreds of datas read, and I feel that opening and closing the SD card that many times seems like a bad idea.

Logged

0
Offline Offline
Edison Member
*
Karma: 64
Posts: 1638
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Newline for Windows is "\r\n" also know as CR/LF.

The Arduino println() function appends "\r\n" for newline. 

Try changing your string like this:

Code:
  String saveThisString="Data:\r\nvalue1=15\r\nvalue2=16\r\nvalue3=4"
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 39
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you ! \r\n solved my problem! my output file is now readable!



Logged

Pages: [1]   Go Up
Jump to: