0

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.

Edited by jrosh

2
Contributors
1
Reply
23
Views
4 Years
Discussion Span
Last Post by gusano79
0

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();
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.