I am using

StingBuilder.append("Address : {0}, {1}, {2}  {3} \n",
                    Street1,
                    Street2,
                    PostalCode,
                    City);

Problem is if Street1 or street2 is null String builder returns

, ,code,city. 

I want to remove those commas(,) as well. how can i do that?

Thank you in advance.

You don't need to append the whole thing at once. One way to address your problem is to append only if you have data:

sb.Append("Address: ");
if(!String.IsNullOrEmpty(Street1)) sb.Append(Street1 + ", ");
if(!String.IsNullOrEmpty(Street2)) sb.Append(Street2 + ", ");
sb.Append("{0} {1}", PostalCode, City);
sb.AppendLine();
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.