Append commas only if strings are not null or empty

If you want to remove the empty or null string you have to filter the array used in the join method:

var array = new[] { address1, address2, city, country, postalCode };
string fullAddress = string.Join(",", array.Where(s => !string.IsNullOrEmpty(s)));

If we make city="" the we have Address1,Address2,Country,00000

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)