Comma separated strings to distinct list conversion in C#
Today we are going to see that how to convert comma separated string to list conversion . I hope we may come across this kind to situation. So it will be more helpful .
string commaSeparatedString ="1,2,3,4,5,,6";
List<string> lstDistinctString = new List<string>();
lstDistinctString = commaSeparatedString.Trim().Split(',').Where(s => !string.IsNullOrWhiteSpace(s)).Distinct().ToList();
Output:
1
2
3
4
5
6
string commaSeparatedString ="1,2,3,4,5,,6";
List<string> lstDistinctString = new List<string>();
lstDistinctString = commaSeparatedString.Trim().Split(',').Where(s => !string.IsNullOrWhiteSpace(s)).Distinct().ToList();
Output:
1
2
3
4
5
6
Comments
Post a Comment