如字符串 “0723-1-邓淑洲、邓家龙”需要分析第二个“-”前一位是否为数字该怎么判断?

解决方案 »

  1.   

     string s = "0723-1-邓淑洲、邓家龙";
                int index1 = s.IndexOf('-');            if (index1 < 0) return; // not int
                int index2 = s.IndexOf('-', index1 + 1);
                if (index2 < 0) return // not int            string ss = s.Substring(index1 + 1, index2 - index1 - 1);
                int result = 0;
                if (int.TryParse(ss, out result))
                {
                    // int
                }
                else
                { 
                    // not int
                }