"abc334de55"字符串中有多少组数字,比如这个是2 "abc334de5533aa44"这个是3, "abcd3343d444ed4ddd5"这个是4 就是连续的数字算是一组,一共多少组
namespace MyNameSpace
{
class MyClass
{
static void Main()
{
int i = new MyClass().CountNumber("12313h12j3h1h23h123h123jh12j3h1j23");
System.Console.WriteLine(i.ToString());
System.Console.ReadKey();
}
public int CountNumber(string str)
{
int count = 0;
bool mark = false;
for (int i = 0; i < str.Length; i++)
{
string s = str[i].ToString();
int j = 0;
if (int.TryParse(s, out j))
{
if (mark == false)
{
mark = true;
count++;
}
}
else
{
if (mark == true)
{
mark = false;
}
}
}
return count;
}
}
}