C Method for Counting the Number of Numbers in String

  • 2021-07-03 00:48:05
  • OfStack

This paper describes the method of counting the number of numbers in string by C #. Share it for your reference. The specific implementation method is as follows:


// DigitCounter.cs
//  Use at compile time: /target:library
using System; 
//  Declaration and  Factorial.cs  The same namespace as the namespace in. This only allows the  
//  Type to the same 1 In the namespace. 
namespace Functions 
{
 public class DigitCount 
 {
  // NumberOfDigits  Static method calculation 
  //  Number of numeric characters in the string passed: 
  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;
  }
 }
}

I hope this article is helpful to everyone's C # programming.


Related articles: