C#統計字符串中數字個數的辦法。本站提示廣大學習愛好者:(C#統計字符串中數字個數的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是C#統計字符串中數字個數的辦法正文
本文實例講述了C#統計字符串中數字個數的辦法。分享給年夜家供年夜家參考。詳細完成辦法以下:
// DigitCounter.cs
// 編譯時應用:/target:library
using System;
// 聲明與 Factorial.cs 中的定名空間雷同的定名空間。如許僅許可將
// 類型添加到統一個定名空間中。
namespace Functions
{
public class DigitCount
{
// NumberOfDigits 靜態辦法盤算
// 傳遞的字符串中數字字符的數量:
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#法式設計有所贊助。