我想格式化地址。這裏是我的代碼:具有空值的String.Format C#
address = String.Format("{0}, {1}, {2}, {3}, {4}, {5}, {6}",
postalAddress.Line1,
postalAddress.Line2,
postalAddress.Line3,
postalAddress.Line4,
postalAddress.Suburb,
postalAddress.StateCode,
postalAddress.Pcode);
很不幸,這會產生116 Knox St, , , , Watson, ACT, 2602
當2號線,3號線,線路4是空的。我如何處理空值以得到如116 Knox St, Watson, ACT, 2602
的結果?
'StringBuilder' +'if'? – zerkms
請你詳細說明一下嗎? – user2994641
你知道'StringBuilder'是什麼嗎? 「if」怎麼樣? – zerkms