C#統(tǒng)計(jì)字符串中數(shù)字個(gè)數(shù)的方法
更新時(shí)間:2015年06月26日 17:53:54 作者:pythoner
這篇文章主要介紹了C#統(tǒng)計(jì)字符串中數(shù)字個(gè)數(shù)的方法,涉及C#遍歷字符串并判斷數(shù)字的技巧,需要的朋友可以參考下
本文實(shí)例講述了C#統(tǒng)計(jì)字符串中數(shù)字個(gè)數(shù)的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:
// DigitCounter.cs // 編譯時(shí)使用:/target:library using System; // 聲明與 Factorial.cs 中的命名空間相同的命名空間。這樣僅允許將 // 類型添加到同一個(gè)命名空間中。 namespace Functions { public class DigitCount { // NumberOfDigits 靜態(tài)方法計(jì)算 // 傳遞的字符串中數(shù)字字符的數(shù)目: public static int NumberOfDigits(string theString) { int count = 0; for ( int i = 0; i < theString.Length; i++ ) { if ( Char.IsDigit(theString[i]) ) { count++; } } return count; } } }
希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。
相關(guān)文章
WinForm項(xiàng)目開發(fā)中Excel用法實(shí)例解析
這篇文章主要介紹了WinForm項(xiàng)目開發(fā)中Excel用法,非常實(shí)用,需要的朋友可以參考下2014-08-08詳解DataGridView控件的數(shù)據(jù)綁定
本文詳細(xì)講解了DataGridView控件的數(shù)據(jù)綁定,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-02-02