Solved

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

Posted on 2008-10-22
6
186 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_
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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 …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

749 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