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