Click here to Skip to main content
15,879,348 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to use stringbuilder for concatinating multiple strings.
this is what i want to convert using string builer..?

C#
if (this.RBLstSeries.SelectedValue == "ELXC")
            {
   this.TxtHdModelNo.Text = this.RBLstSeries.SelectedValue.ToString() + "-" + this.RBLstDamper.SelectedValue.Substring(0, 3).ToString() + "-" + this.RBLstStyle.SelectedValue.Substring(0, 1).ToString() + "-" + this.RBLstFrontLipDesign.SelectedValue.Substring(0, 1).ToString() + "-" + this.RBLstApronDesign.SelectedValue.Substring(0, 1).ToString();
Posted
Updated 24-May-12 19:03pm
v2

1 solution

You could have something like (not tested):
C#
StringBuilder sb = new StringBuilder();
sb.AppendFormat("{0}-{1}-{2}-{3}-{4}",
   this.RBLstSeries.SelectedValue.ToString(),
   this.RBLstDamper.SelectedValue.Substring(0, 3).ToString(),
   this.RBLstStyle.SelectedValue.Substring(0, 1).ToString(),
   this.RBLstFrontLipDesign.SelectedValue.Substring(0, 1).ToString(),
   this.RBLstApronDesign.SelectedValue.Substring(0, 1).ToString());
this.TxtHdModelNo.Text = sb.ToString();

Refer to StringBuilder Class[^] and StringBuilder.AppendFormat Method (String, Object[])[^]
 
Share this answer
 
Comments
Sandeep Mewara 25-May-12 1:28am    
5!
Wendelius 31-May-12 14:14pm    
Thanks :)
VJ Reddy 25-May-12 6:33am    
Good use of AppendFormat 5!
Wendelius 31-May-12 14:14pm    
Thanks :)
BillW33 25-May-12 16:21pm    
Very nice, +5 :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900