Determining whether a comma delimited string comprising a string

Such as string str = "1,21,32,44,55"

If the direct comma + contains the string is determined, then, for example, "1," there will be problems, there are two methods

if (strt.StartsWith(name+",")||
    strt.Contains(","+name+",")||
    str.EndsWith(","+name))
{

}
////////////////////////方式1//////////////////////////////
String[] listValues = strSplit(',');
if (listValues.Contains(name))
{

}
////////////////////////方式2////////////////////////////////

 

Guess you like

Origin www.cnblogs.com/zhaogaojian/p/11479674.html