Format strings to be a consistent width?  [SOLVED]

Questions about MultiCharts and user contributed studies.
Xyzzy
Posts: 162
Joined: 19 Mar 2011
Has thanked: 43 times
Been thanked: 79 times

Format strings to be a consistent width?

Postby Xyzzy » 17 Dec 2013

I'll often use code like this to generate print logs in the output window:

Code: Select all

Print(Symbol, " ", CurrentEntries:10:0, Close:10:2);
I use the ":" operator with numeric entries to help them line up in neat columns. However, the strings don't necessary line up (since they have different widths), so I end up with output like:

Code: Select all

KRFT 0 52.56
LBTYA 0 83.95
LIFE 0 75.64
LINTA 0 27.88
LLTC 0 44.45
MAT 1 44.69
MCHP 0 42.08
Is there a native keyword or function in MultiCharts to force the strings to be a consistent width? I.e., to pad shorter strings with additional spaces so that they all have the same width? (Unfortunately, the ":" operator doesn't have any effect on strings.)

I wrote a short function to do this (below), but I'm not sure if I'm reinventing the wheel. Many thanks in advance.

Code: Select all

Inputs:
Source(String),
Length(NumericSimple);

If StrLen(Source) >= Length then begin
_PadStr = Source;
end else begin
_PadStr = Source + Spaces(Length - StrLen(Source));
end;

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 559 times

Re: Format strings to be a consistent width?  [SOLVED]

Postby Andrew MultiCharts » 18 Dec 2013

Hello Xyzzy,

Thanks for functions, you are not re-inventing anything, there is no such prebuilt keyword.

Xyzzy
Posts: 162
Joined: 19 Mar 2011
Has thanked: 43 times
Been thanked: 79 times

Re: Format strings to be a consistent width?

Postby Xyzzy » 18 Dec 2013

Thanks Henry. It would be a nice feature if we could use the ":" operator for strings, so I could do something like:

Code: Select all

Print(Symbol:5, " ", CurrentEntries:10:0, Close:10:2);
This would be cleaner than calling a function inside the print statement. I'll submit a feature request for this.


Return to “MultiCharts”