2 registered members (TedMar, AndrewAMD),
1,344
guests, and 7
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Why \n does not work?
#413176
12/09/12 19:24
12/09/12 19:24
|
Joined: Apr 2011
Posts: 75 Malta
Ercoles
OP
Junior Member
|
OP
Junior Member
Joined: Apr 2011
Posts: 75
Malta
|
I need to print text on more than 1 line using \n in the string to go to the next line and I need to read the text from a text file. I am using:
TEXT* message_txt = { pos_x = 0; pos_y = 0; layer = 2; font = arial2_font; string(mes_str); flags = SHOW; }
to display the text.
Now if I us the str_cpy function to copy a string containing \n using:
str_cpy(mes_str,message_str);
If message_str is created in the program with:
STRING* message_str = "This is a\n test";
it works OK. eg.
This is a test
However if I load the string from a text file with:
var filehandle = file_open_read ("test.txt"); // test.txt contains the string "This is a\n test" file_str_read(filehandle,message_str); file_close (filehandle);
and then use the str_cpy to copy to the TEXT panel.
It will print "This is a\n test" and not
This is a test
Any solution?
Last edited by Ercoles; 12/09/12 19:26.
|
|
|
Re: Why \n does not work?
[Re: Ercoles]
#413177
12/09/12 19:39
12/09/12 19:39
|
Joined: Jun 2009
Posts: 2,210 Bavaria, Germany
Kartoffel
Expert
|
Expert
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
|
I don't know why this doesn't work but using a , in a text file also creates a new line. So it would be "This is a,test"
Last edited by Kartoffel; 12/09/12 19:40.
POTATO-MAN saves the day! - Random
|
|
|
Re: Why \n does not work?
[Re: Kartoffel]
#413179
12/09/12 20:14
12/09/12 20:14
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
Expert
Joined: Jan 2002
Posts: 4,225
Germany / Essen
|
Writing "\n" within in a string in your sourcecode will cause the compiler to convert that escape sequence to the proper replacement. When reading bytes from a file there is no conversion though. I also don't see any reason why there should be a conversion when reading characters from a file..?
The comma does not create a line feed but separates two strings from each other if and only if you haven't changed the delimiter char previously.
Always learn from history, to be sure you make the same mistakes again...
|
|
|
Re: Why \n does not work?
[Re: Uhrwerk]
#413183
12/09/12 20:42
12/09/12 20:42
|
Joined: Jun 2009
Posts: 2,210 Bavaria, Germany
Kartoffel
Expert
|
Expert
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
|
Well, then sorry for my misleading post. ...just saw this: Aside from the division into separate strings, the file content won't be modified, f.i. "\n" characters will not be converted to line feeds.
POTATO-MAN saves the day! - Random
|
|
|
Re: Why \n does not work?
[Re: Kartoffel]
#413184
12/09/12 20:49
12/09/12 20:49
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
Expert
Joined: Jan 2002
Posts: 4,225
Germany / Essen
|
It wasn't misleading. It's exactly what it does for example when using txt_load. I just wanted to add the delimit_str info.
Always learn from history, to be sure you make the same mistakes again...
|
|
|
Re: Why \n does not work?
[Re: Uhrwerk]
#413244
12/10/12 19:20
12/10/12 19:20
|
Joined: Apr 2011
Posts: 75 Malta
Ercoles
OP
Junior Member
|
OP
Junior Member
Joined: Apr 2011
Posts: 75
Malta
|
I found a solution to this, in the file I changed all \n to %nl% then after reading the string from the file I use:
STRING* linefeed="\n";
...
str_replaceall(gs,"%nl%",linefeed);
where gs is the string just read from the file. Now gs contains a string with \n which work OK
Last edited by Ercoles; 12/10/12 19:21.
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|