Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- 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.
- */
- public static int FindCountInString(string full, int num)
- {
- string numberAsString = num.ToString();
- int numFound = 0;
- for(int i = 0; i < full.Length-numberAsString.Length+1; i++)
- {
- bool foundNumber = true;
- for(int j = 0; j < numberAsString.Length; j++)
- {
- if (full[i+j] != numberAsString[j])
- {
- foundNumber = false;
- break;
- }
- }
- if (foundNumber)
- {
- numFound++;
- }
- }
- return numFound;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement