Solved

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

Posted on 2008-10-22
6
183 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
Comment Utility
   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_
Comment Utility
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
Comment Utility
Hello toshi_,

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

Regards,

TimCottee
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:toshi_
Comment Utility
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
Comment Utility
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_
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
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 …

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now