"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;
}
}
}
本文介绍了一种方法来计算给定字符串中连续数字序列的数量。通过遍历字符串并检查每个字符是否为数字来实现这一目标。当从非数字字符转换到数字字符时,计数器增加。
3435

被折叠的 条评论
为什么被折叠?



