[C#] C#统计字符串中数字的个数 →→→→→进入此内容的聊天室

来自 , 2020-09-16, 写在 C#, 查看 168 次.
URL http://www.code666.cn/view/3bd7ef30
  1. // DigitCounter.cs
  2. // 编译时使用:/target:library
  3. using System;
  4.  
  5. // 声明与 Factorial.cs 中的命名空间相同的命名空间。这样仅允许将
  6. // 类型添加到同一个命名空间中。
  7. namespace Functions
  8. {
  9.     public class DigitCount
  10.     {
  11.         // NumberOfDigits 静态方法计算
  12.         // 传递的字符串中数字字符的数目:
  13.         public static int NumberOfDigits(string theString)
  14.         {
  15.             int count = 0;
  16.             for ( int i = 0; i < theString.Length; i++ )
  17.             {
  18.                 if ( Char.IsDigit(theString[i]) )
  19.                 {
  20.                     count++;
  21.                 }
  22.             }
  23.             return count;
  24.         }
  25.     }
  26. }
  27. //csharp/4917

回复 "C#统计字符串中数字的个数"

这儿你可以回复上面这条便签

captcha