Advertisement
Guest User

Untitled

a guest
Jan 19th, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.99 KB | None | 0 0
  1. /*
  2.             This method loops through the passed string, and then checks if the passed number in base 10 is there, if it is it adds one to a counter. When it has looped through the entire passed string it returns the final counter count.
  3.         */
  4.         public static int FindCountInString(string full, int num)
  5.         {
  6.             string numberAsString = num.ToString();
  7.             int numFound = 0;
  8.  
  9.             for(int i = 0; i < full.Length-numberAsString.Length+1; i++)
  10.             {
  11.  
  12.                 bool foundNumber = true;
  13.                 for(int j = 0; j < numberAsString.Length; j++)
  14.                 {
  15.                     if (full[i+j] != numberAsString[j])
  16.                     {
  17.                         foundNumber = false;
  18.                         break;
  19.                     }
  20.                 }
  21.                
  22.                 if (foundNumber)
  23.                 {
  24.                     numFound++;
  25.                 }
  26.  
  27.             }
  28.  
  29.             return numFound;
  30.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement