日期:2014-05-20 浏览次数:21099 次
string str="2, ,12,31,27,54,0,,6,56,";
String[] array=str.Split(new String[1]{","},StringSplitOptions.RemoveEmptyEntries);
foreach(str s in array)
  if(Convert.ToInt32(s)>50)
  {
    Console.WriteLine("大于50.")
    Break;
  }
------解决方案--------------------
static void Main(string[] args)
        {
            string str = "2, ,12,31,27,54,0,,6,56,";
            String[] array = str.Split(new String[1] { "," }, StringSplitOptions.RemoveEmptyEntries);
            List<int> arrayList = new List<int>();
            foreach (string s in array)
                if (s.Trim() != "")
                    arrayList.Add(Convert.ToInt32(s));
            //搜索数组中是否有大于50的数字,前面将字符串按逗号分隔
            if (arrayList.Where(r => r > 50).Count() > 0)
                Console.WriteLine("error");
            Console.ReadLine();
        }
------解决方案--------------------
string value = "2, ,12,31,27,50,0,,6,50,";
MessageBox.Show(System.Text.RegularExpressions.Regex.IsMatch(value, "\\,[ ]*((5[1-9])|[6-9][\\d])|([1-9][\\d]{2,})[ ]*\\,", System.Text.RegularExpressions.RegexOptions.IgnoreCase));
------解决方案--------------------
bool have = "2, ,12,31,27,54,0,,6,56,".Split(',').Where(x => x.Trim() != "").Any(x => Convert.ToInt32(x) > 50);
------解决方案--------------------
string str = "2, ,12,31,27,54,0,,6,56,";
var datainfoList = str.Split(new string[] { "、" }, StringSplitOptions.RemoveEmptyEntries).ToList();
          
 if (datainfoList.Any(t => Convert.ToDouble(t) > 50))
 {
       throw new Exception("输入的数据有误!");
 }