Solved

is it possible to format a string while appending lines to stringbuilder?

Posted on 2008-10-22
6
184 Views
Last Modified: 2013-12-17
hello experts,

for my test necessities,
i feed a stringbuilder in order to display values of object to the console.

how can i have the following lines formated as :

 if(EcowastePosition_ != null)
                {
                    sb.Append("\nAddress:"          + obj.Address);
                    sb.Append("\nAddressNo:"        + obj.AddressNo);
                    sb.Append("\nCity:"             + obj.PostalNo);
}

....
....
Console.write(sb.tostring());

i 'd like to view :
Address                anAddress
AddressNo            aNo
City                       aCity

i'd like to have the second column, the values, in a vertical line alined.

thank you..
0
Comment
Question by:toshi_
  • 3
  • 2
6 Comments
 
LVL 23

Expert Comment

by:Kamaraj Subramanian
ID: 22774854
   sb.Append("\nAddress:\t\t"          + obj.Address);
                    sb.Append("\nAddressNo:\t\t"        + obj.AddressNo);
                    sb.Append("\nCity:\t\t"             + obj.PostalNo);
0
 

Author Comment

by:toshi_
ID: 22774879
it wouldnt work that easy , thank you for the reply
but my second column is not alined

is there another possibitliy?



0
 
LVL 43

Accepted Solution

by:
TimCottee earned 250 total points
ID: 22775033
Hello toshi_,

sb.Append("\nAddress:".PadRight(20)).Append(obj.Address);
sb.Append("\nAddressNo:".PadRight(20)).Append(obj.AddressNo);
etc

Regards,

TimCottee
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:toshi_
ID: 22775983
thank you TimCottee,
but i still missing something.
as example look at the display here under.

Id Ecopoint:.................1006
Id Ecolog:...................1572871
Id Weight System:............1572871

but even with the second parameter filled with '.' my columns are not alined,

is it possible to have a result as follow,?

Id Ecopoint:........................1006
Id Ecolog:...........................1572871
Id Weight System:............1572871

0
 
LVL 43

Expert Comment

by:TimCottee
ID: 22776079
toshi_,

Didn't realise it was for HTML output. The issue here is most likely that you have a proportional font so any padding in this way is not going to have the desired effect. One solution to that would be to create a table within your  or either multiple columns using  or

sb.Append("\nAddress:").Append(obj.Address).Append("")
sb.Append("\nAddressNo:").Append(obj.AddressNo).Append("")
sb.Append("\nCity:").Append(obj.City).Append("").Append("")

Or

sb.Append("")
sb.Append("Address:AddressNo:City")
sb.Append("").Append(obj.Address).Append("").Append(obj.AddressNo).Append("").Append(obj.City).Append("")
sb.Appemd("")

TimCottee
0
 

Author Comment

by:toshi_
ID: 22776255
thank you very much timCottee,

i notice now , while debugging that on a fixed width font
the display is exactly what i was lookiing for....

i just need to change my NUnit to use a fixed width font.

cheers.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A short article about a problem I had getting the GPS LocationListener working.
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question