Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (TedMar, AndrewAMD), 1,344 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
LucasJoshua, Baklazhan, Hanky27, firatv, wandaluciaia
19053 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Why \n does not work? #413176
12/09/12 19:24
12/09/12 19:24
Joined: Apr 2011
Posts: 75
Malta
E
Ercoles Offline OP
Junior Member
Ercoles  Offline OP
Junior Member
E

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 Offline
Expert
Kartoffel  Offline
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 Offline
Expert
Uhrwerk  Offline
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 Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Well, then sorry for my misleading post.

...just saw this:
Originally Posted By: Manual
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 Offline
Expert
Uhrwerk  Offline
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] #413185
12/09/12 20:53
12/09/12 20:53
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
...then it's just my bad english grin


POTATO-MAN saves the day! - Random
Re: Why \n does not work? [Re: Kartoffel] #413186
12/09/12 20:57
12/09/12 20:57
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
... or my Korinthenkacking grin


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
E
Ercoles Offline OP
Junior Member
Ercoles  Offline OP
Junior Member
E

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.

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1