Solved

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

Posted on 2008-10-22
6
187 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
Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

 

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

Increase Agility with Enabled Toolchains

Connect your existing build, deployment, management, monitoring, and collaboration platforms. From Puppet to Chef, HipChat to Slack, ServiceNow to JIRA, Splunk to New Relic and beyond, hand off data between systems to engage the right people.

Connect with xMatters.

Question has a verified solution.

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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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 …
Introduction to Processes

696 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