日期:2014-05-17  浏览次数:20415 次

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

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

------解决方案--------------------

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;
    }                
}

------解决方案--------------------
 int index = Regex.Match("abcdef123der", "\\d").Index;