If you want to know if there is more then one value in the comma separated string you could use the method that Avinash suggested (meaning the string "String1,String2,String1" contains 3 values).
If you would like to know if a specific string exists more then once in the comma separated string you could use something like this (quick and dirty):
public static bool ContainDoubleValues(string csvString, string separator)
{
List<String> listOfValues = new List<string>();
string[] values = csvString.Split(separator.ToCharArray());
foreach(string value in values)
if(listOfValues.Contains(value))
return true;
return false;
}
mvanbeusekom
Member
134 Points
26 Posts
Test code post
Jan 18, 2010 10:07 AM|LINK
Hi Ryanlcs,
If you want to know if there is more then one value in the comma separated string you could use the method that Avinash suggested (meaning the string "String1,String2,String1" contains 3 values).
If you would like to know if a specific string exists more then once in the comma separated string you could use something like this (quick and dirty):
public static bool ContainDoubleValues(string csvString, string separator) { List<String> listOfValues = new List<string>(); string[] values = csvString.Split(separator.ToCharArray()); foreach(string value in values) if(listOfValues.Contains(value)) return true; return false; }Blog: http://blog.themobilebrand.com