c#统计字符串中数字字符的个数【C#】
生活随笔
收集整理的這篇文章主要介紹了
c#统计字符串中数字字符的个数【C#】
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
c#統(tǒng)計(jì)字符串中數(shù)字字符的個(gè)數(shù)
題目描述
假設(shè)有一個(gè)GetNumber方法(參數(shù)為字符串strSource),編寫一個(gè)靜態(tài)方法可以用來(lái)統(tǒng)計(jì)字符串strSource中數(shù)字字符的個(gè)數(shù)。
輸入
輸入一個(gè)字符串strSource輸出
strSource字符串中數(shù)字字符的個(gè)數(shù)樣例輸入
style="color:#333333">asffkl8asjkfjklas3jdf9lkj!樣例輸出
3 using System; using System.Collections;namespace sample {class Program{static int GetNumber(string strSource){int num=0;for (int i = 0; i < strSource.Length; i++){if(strSource[i] >= '0' && strSource[i] <= '9'){num++;}}return num;}static void Main(string[] args){string strSource = Console.ReadLine();Console.WriteLine(GetNumber(strSource));}} }?
總結(jié)
以上是生活随笔為你收集整理的c#统计字符串中数字字符的个数【C#】的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: W3C近期要闻:W3C战略重点报告新版发
- 下一篇: 深入理解Angular订阅者模式