判斷一個數值是否在一個逗號分隔的字符串中


  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
  }
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM