問題 C: c#統計字符串中數字字符的個數


題目描述

假設有一個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);
        }
    }
}

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM