判断一个数值是否在一个逗号分隔的字符串中

  1. 使用表达式方式:
string s = "12,123,1234,32,321,345";
if (s.Split(',').Any(x => x == "12"))
     //存在
 
    2.
      string a = "1,2,3,4,5,6";
  if(a.IndexOf(“3,")>-1)
  {
   //字符串A中包含字符串B
  }
      string a = "1,2,3,4,5,6";
  List<string> oTempList = new List<string>(a.Split(','}));
  if(oTempList.Contains(“3"))
  {
   //字符串数据A中包含字符串元素B
  }
 
posted @ 2017-01-10 17:20  孔小爽  阅读(3219)  评论(0编辑  收藏  举报
作者:孔小爽 引用请标明出处:https://www.cnblogs.com/kongxiaoshuang/