OJ Problem 3445 c#统计字符串中数字字符的个数

题目描述

假设有一个GetNumber方法(参数为字符串strSource),编写一个静态方法可以用来统计字符串strSource中数字字符的个数。 

输入

输入一个字符串strSource

输出

strSource字符串中数字字符的个数

样例输入

asffkl8asjkfjklas3jdf9lkj!

样例输出

3

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Security.Cryptography;
using System.IO;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string strSource = Console.ReadLine();
            int count=0;
            for(int i=0;i<strSource.Length;i++)
            {
                if(strSource[i]>='0'&&strSource[i]<='9')
                {
                    count++;
                }
            }
            Console.WriteLine(count);
        }
    }
} 

猜你喜欢

转载自blog.csdn.net/wangws_sb/article/details/105111505