forum

Home / DeveloperSection / Forums / String.Format with null values C#

String.Format with null values C#

Anonymous User 7572 12-Dec-2013

I want to format an address. Here is my code:

address = String.Format("{0}, {1}, {2}, {3}, {4}, {5},
{6}",
                        postalAddress.Line1,
postalAddress.Line2,
                        postalAddress.Line3,
                        postalAddress.Line4,
                        postalAddress.Suburb,
                        postalAddress.StateCode,
                        postalAddress.Pcode);
Unfortunately this produces 116 Knox St, , , , Watson, ACT, 2602 when Line2, Line3, Line4 are null. How can I handle the nulls to get a results like 116 Knox St, Watson, ACT, 2602?

c# c# 
Updated on 12-Dec-2013
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By