Thursday, March 22, 2012

Maintaining string positions

Hi,

I get 6 strings with different values each time.I need to align themselves 3 in each row with each of them justified.I used padright with empty space to align themselves.The problem is my strings are becoming unaligned if the string length increases or decreases.Is there anyway that we can specify each string should be between a specified length.For example below i want string1-string6 should be always be 20 in length.

String1 String2 String3

String4 String5 String6

If i used padleft for particular data i am able to do it but if i use the same for a different data the strings will not alin as the length of them changes.

Hi,

you need to change the font... set font of the control as 'Courier New' in which you are printing the string.....


I guess u got me wrong wht iam intended to say is string1 should occupy 50 bytes irrespective of its length.Suppose it is 30bytes it has to occupy 50 bytes with 20 spaces added after it.Same for all the strings...


why not just put them into a 3 column, 2 row table? that would be a simple solution.


Hi,

try this one...

string item = "Vasanth";

if(item.length > 50)

{

item = item.substring(0,50);

}

else

{
for (int i = item.Trim().Length; i < 50; i++)
{
item = item + " ";
}

}


Finally your string will get 50 length... irrespective of the original length

0 comments:

Post a Comment