Recently on ASP.NET forum there was post for removing duplicate ',' from a comma saperated string.
This is using Regex
string abodes = ",House,,,,Apartment,,,Villa,,,,Townhouse,,,,";And now let's see using LINQ
Regex regx = new Regex(@",+");
abodes = regx.Replace(abodes, ",").Trim(',');
string abodes = ",House,,,,Apartment,,,Villa,,,,Townhouse,,,,";Have Fun with LINQ
string cleanAbodes = string.Join(",", abodes.Split(',').Where(a => a != string.Empty).ToArray());
No comments:
Post a Comment