C#統(tǒng)計字符串中數(shù)字個數(shù)的方法
更新時間:2015年06月26日 17:53:54 作者:pythoner
這篇文章主要介紹了C#統(tǒng)計字符串中數(shù)字個數(shù)的方法,涉及C#遍歷字符串并判斷數(shù)字的技巧,需要的朋友可以參考下
本文實例講述了C#統(tǒng)計字符串中數(shù)字個數(shù)的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:
// DigitCounter.cs
// 編譯時使用:/target:library
using System;
// 聲明與 Factorial.cs 中的命名空間相同的命名空間。這樣僅允許將
// 類型添加到同一個命名空間中。
namespace Functions
{
public class DigitCount
{
// NumberOfDigits 靜態(tài)方法計算
// 傳遞的字符串中數(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;
}
}
}
希望本文所述對大家的C#程序設計有所幫助。
相關文章
詳解DataGridView控件的數(shù)據(jù)綁定
本文詳細講解了DataGridView控件的數(shù)據(jù)綁定,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-02-02

