Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/25/24 10:20
Trading Journey
by howardR. 04/24/24 20:04
M1 Oversampling
by Petra. 04/24/24 10:34
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
folder management functions
by VoroneTZ. 04/17/24 06:52
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (EternallyCurious, Quad, vicknick), 700 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mega_Rod, EternallyCurious, howardR, 11honza11, ccorrea
19048 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Separate string into multiple lines #483517
06/08/21 23:17
06/08/21 23:17
Joined: Apr 2021
Posts: 41
Slovakia
T
tomna1993 Offline OP
Newbie
tomna1993  Offline OP
Newbie
T

Joined: Apr 2021
Posts: 41
Slovakia
Hi,
I have a long string which I use for formatting data I want to save. It looks like this:
Code
string LogDataFormat = "%s,%i,%s,%i,%.15f,%.15f,%i,%i,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%i,%.2f,%.2f,%.2f,%.2f,%.2f,%i,%.2f,%i,%.2f,%.2f,%.2f,%i,%.2f,%.2f,%i%i,%i,%i%i,%.2f\n";


I want to separate it to multiple rows to be much more readable, if it is possible use comment for each row. I already tried one solution which works in C but the formatting of my data in log file was exactly the same looking as the multirow string:

Code
string LogDataFormat = "%s,\
%i,\
%s,\
%i,\
%.15f,%.15f,\
%i,%i,%.2f,%.2f,\
%.2f,%.2f,\
%.2f,%.2f,\
%i,%.2f,\
%.2f,%.2f,\
%.2f,%.2f,\
%i,%.2f,\
%i,%.2f,\
%.2f,%.2f,\
%i,%.2f,\
%.2f,\
%i%i,%i,%i%i,\
%.2f\n";


Is there any solution to format that string much more readable in Lite-c?

Re: Separate string into multiple lines [Re: tomna1993] #483519
06/09/21 07:27
06/09/21 07:27
Joined: May 2015
Posts: 390
Czech Republic
G
Grat Offline
Senior Member
Grat  Offline
Senior Member
G

Joined: May 2015
Posts: 390
Czech Republic
mayby:
Code
string LogDataFormat = "%s,
%i,
%s,
%i,
..
%.2f";

Re: Separate string into multiple lines [Re: Grat] #483521
06/09/21 07:56
06/09/21 07:56
Joined: Apr 2021
Posts: 41
Slovakia
T
tomna1993 Offline OP
Newbie
tomna1993  Offline OP
Newbie
T

Joined: Apr 2021
Posts: 41
Slovakia
Already tried it, does not work.

Re: Separate string into multiple lines [Re: tomna1993] #483524
06/09/21 09:27
06/09/21 09:27
Joined: Aug 2017
Posts: 294
Netherlands
G
Grant Offline
Member
Grant  Offline
Member
G

Joined: Aug 2017
Posts: 294
Netherlands
Replace the string type with char* in your second code example.

Re: Separate string into multiple lines [Re: Grant] #483526
06/09/21 10:01
06/09/21 10:01
Joined: Apr 2021
Posts: 41
Slovakia
T
tomna1993 Offline OP
Newbie
tomna1993  Offline OP
Newbie
T

Joined: Apr 2021
Posts: 41
Slovakia
It still gives the same result.

I think I wrongly described my problem. The code I included works nice in a manner of code readability but in my log file it looks like on the attached picture. I want to log each trade in separate rows and also print a header for my file in one row like a csv document (see picture). The problem is, that the code I included in the first post puts each word in new row and puts a "\r" characters after the comma.

Attached Files Annotation 2021-06-09 115945.pngAnnotation 2021-06-09 120821.png
Last edited by tomna1993; 06/09/21 10:08.
Re: Separate string into multiple lines [Re: tomna1993] #483529
06/09/21 14:05
06/09/21 14:05
Joined: Aug 2017
Posts: 294
Netherlands
G
Grant Offline
Member
Grant  Offline
Member
G

Joined: Aug 2017
Posts: 294
Netherlands
OK, can you try this?

string LogDataFormat = "%s,\n\
%i,\n\
%s,\n\
%i,\n\
%.15f,%.15f,\n\
%i,%i,%.2f,%.2f,\n\
%.2f,%.2f,\n\
%.2f,%.2f,\n\
%i,%.2f,\n\
%.2f,%.2f,\n\
%.2f,%.2f,\n\
%i,%.2f,\n\
%i,%.2f,\n\
%.2f,%.2f,\n\
%i,%.2f,\n\
%.2f,\n\
%i%i,%i,%i%i,\n\
%.2f\n";

(or else LogDataFormat as char*)

Last edited by Grant; 06/09/21 14:50.
Re: Separate string into multiple lines [Re: Grant] #483530
06/09/21 20:55
06/09/21 20:55
Joined: Apr 2021
Posts: 41
Slovakia
T
tomna1993 Offline OP
Newbie
tomna1993  Offline OP
Newbie
T

Joined: Apr 2021
Posts: 41
Slovakia
Same result.

Re: Separate string into multiple lines [Re: tomna1993] #483531
06/09/21 21:50
06/09/21 21:50
Joined: Aug 2017
Posts: 294
Netherlands
G
Grant Offline
Member
Grant  Offline
Member
G

Joined: Aug 2017
Posts: 294
Netherlands
Sorry to hear. I've tried the following simple example that works fine, but I have no clue on how you've implemented this LogDataFormat string, so can you show me your code?

char* LogDataFormat = "Trade 1.\n\Trade 2.\n\Trade 3.";
print(TO_CSV, LogDataFormat);

Re: Separate string into multiple lines [Re: Grant] #483533
06/10/21 08:51
06/10/21 08:51
Joined: Apr 2021
Posts: 41
Slovakia
T
tomna1993 Offline OP
Newbie
tomna1993  Offline OP
Newbie
T

Joined: Apr 2021
Posts: 41
Slovakia
I use file append to add information to the txt file.
Code
file_append(LogDestination, LogHeader, 0)
file_append(LogDestination, LogData, 0)

And use the formatting to save the informations formatted to LogData String.
Code
strcat(LogData, strf(LogDataFormat, (string)Log_Asset,
(int)TradeID, 
(string)Log_TradeDirection, 
(int)Log_TradeTimeFrame, 
(var)TradeDate, 
(var)TradeExitDate, 
(int)TradeBars, 
(int)Lots, 
(var)TradePriceOpen, 
));

Re: Separate string into multiple lines [Re: tomna1993] #483549
06/14/21 07:13
06/14/21 07:13
Joined: Jul 2000
Posts: 27,982
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,982
Frankfurt
If I understand it right, you want the format string to go over several lines in your source code, but behave as if it were a single line.

I think this won't work in lite-C. You can do it with #defines, but not with strings.

Re: Separate string into multiple lines [Re: tomna1993] #483552
06/14/21 09:45
06/14/21 09:45
Joined: Aug 2017
Posts: 294
Netherlands
G
Grant Offline
Member
Grant  Offline
Member
G

Joined: Aug 2017
Posts: 294
Netherlands
It's not the most elegant solution, but you could try one of the following substring methods when your string has a fixed length,

https://www.programmingsimplified.com/c/source-code/c-substring

Re: Separate string into multiple lines [Re: jcl] #483562
06/15/21 09:51
06/15/21 09:51
Joined: Apr 2021
Posts: 41
Slovakia
T
tomna1993 Offline OP
Newbie
tomna1993  Offline OP
Newbie
T

Joined: Apr 2021
Posts: 41
Slovakia
You understand it right!

Grant: yeah, the problem is that the length is not fixed. I hoped this to be easier (like in C) but doesn't matter, I fight with it. That is the easiest part of the program, the debugging both visually and by values are more pain in the ass.

Thanks for both of your help and have a nice day!

Re: Separate string into multiple lines [Re: tomna1993] #483563
06/15/21 10:57
06/15/21 10:57
Joined: Aug 2017
Posts: 294
Netherlands
G
Grant Offline
Member
Grant  Offline
Member
G

Joined: Aug 2017
Posts: 294
Netherlands
Within Excel I use the LEN() and MID() functions for a similar scenario with non-fixed string lengths, but in your case I believe it would be much easier to work with an array.
Best of luck and have a nice day as well.

Re: Separate string into multiple lines [Re: Grant] #483567
06/16/21 12:42
06/16/21 12:42
Joined: Apr 2021
Posts: 41
Slovakia
T
tomna1993 Offline OP
Newbie
tomna1993  Offline OP
Newbie
T

Joined: Apr 2021
Posts: 41
Slovakia
Later on I will check your idea! Thanks!

Page 1 of 2 1 2

Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1