码迷,mamicode.com
首页 > Windows程序 > 详细

问题 C: c#统计字符串中数字字符的个数

时间:2020-03-26 19:12:23      阅读:106      评论:0      收藏:0      [点我收藏+]

标签:using   OLE   ++   generic   string   sha   readline   content   collect   

题目描述

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

输入

输入一个字符串strSource

输出

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

样例输入

.wrapper {position: relative;} #input {position: absolute;top: 0;left: 0;opacity: 0;z-index: -10;}

asffkl8asjkfjklas3jdf9lkj!

样例输出

3
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace 统计字符串中数字字符的个数
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            int count = 0;
            for (int i = 0; i < s.Length; ++i)
            {
                if (s[i] >= ‘0‘ && s[i] <= ‘9‘)
                {
                    count++;
                }
            }
            Console.WriteLine(count);
        }
    }
}

  

问题 C: c#统计字符串中数字字符的个数

标签:using   OLE   ++   generic   string   sha   readline   content   collect   

原文地址:https://www.cnblogs.com/mjn1/p/12576459.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!