asp.net中在一个字符串中判断包含在里面的数字位置。例如abcdef123der,怎么才能知道这个字符串中数字在那个位置。ASP.NET

解决方案 »

  1.   

     string txt = "abcdef123der";
                Console.WriteLine("数字的位置是:{0}", txt.IndexOf(Regex.Match(txt, @"\d+").Groups[0].Value));
      

  2.   


    string txt = "abcdef123der";
    for (int i = 0; i < txt.Length; i++)

        int parse;
        if (int.TryParse(txt[i].ToString(),out parse))
        {
            Console.Write("位置:" + i.ToString());
            break;
        }                
    }
      

  3.   

     int index = Regex.Match("abcdef123der", "\\d").Index;