![]() |
This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Junior Member
Join Date: Jan 2011
Posts: 11
Thanks: 0
Thanked 0 times in 0 posts
|
Dear all,
I am dealing with a text problem. It is that if a want to display a 3*3 ( or other size) string matrix, for example string text = "aa b ccc\na bb c\naaa\nbb cc\n" while using DrawText method, we will get: aa_b_ccc a_bb_c aaa_bb_cc is there any way that we can get: aa___b___ccc a____bb__c aaa__bb__cc how to align each column like that? Thanks
Last edited by keven; 02-18-2011 at 05:37 PM.
|
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,411
Thanks: 252
Thanked 976 times in 959 posts
|
keven, not sure I follow - what is the difference exactly in your two examples? Could you please clarify for us?
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Junior Member
Join Date: Jan 2011
Posts: 11
Thanks: 0
Thanked 0 times in 0 posts
|
Oh, sorry, my mistake. the system trim the redundant blanks between the strings automatically.
let me use _ to replace blank. now the example looks like: aa_b_ccc a_bb_c aaa_bb_cc is there any way that we can get: aa___b___ccc a____bb__c aaa__bb__cc in other words, how to align the string of each column ? Thanks |
|
|
|
|
|
#4 |
|
Senior Member
|
Can you not just backpad your strings with spaces to force them to line up?
|
|
|
|
|
|
#5 |
|
Junior Member
Join Date: Jan 2011
Posts: 11
Thanks: 0
Thanked 0 times in 0 posts
|
but the thing is I don't know the length of each string.
do we have some method to set the field width of the string ? Thanks |
|
|
|
|
|
#6 |
|
Junior Member
Join Date: May 2010
Location: Laramie, WY
Posts: 24
Thanks: 0
Thanked 1 time in 1 post
|
You can align values in a string fairly easily using String.Format(),
For example, if you want your values to be left padded every 5 spaces (For a,b,c values) you can do something like this: String.Format("{0, -5} {1, -5} {2, -5}", a,b,c) For Right aligned, use 5 instead of -5. This will work fine for any integer that is 5 characters or less, feel free to adjust to your needs as 5 might be too wide. You can use \n in the Format or string 3 of them together, whichever is more readable to you. I believe that should work as you desire with DrawText(). edit: I typod (should be 0, 1, 2 like usual in {}) plus here's a full example! Code:
protected override void OnBarUpdate()
{
int a = 123;
int b = 321;
int c = 12;
DrawText("textTag1", String.Format("{0, -5} {1,-5} {2,-5}", a,b,c), 0, Close[0], Color.Red);
Plot0.Set(Close[0]);
}
Last edited by Dexter; 02-18-2011 at 06:35 PM.
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help with DrawText() to draw text vertically | abmninja | General Programming | 2 | 10-18-2010 12:51 PM |
| DrawText method | tamas | Version 7 Beta General Questions & Bug Reports | 2 | 08-23-2010 12:54 AM |
| No overload for method 'DrawText' error | badasan | Version 7 Beta General Questions & Bug Reports | 3 | 05-04-2010 05:13 PM |
| Display Bug in DrawText Method | KBJ | General Programming | 6 | 06-12-2009 05:21 AM |
| Positioning text using DrawText() | higler | General Programming | 7 | 07-15-2008 01:36 AM |