Created
November 2, 2017 09:11
-
-
Save Hameds/9bb4fa64ff48c56b452de5ced736b2b0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| namespace ThirtyDaysOfTDD.UnitTests | |
| { | |
| public class StringUtils | |
| { | |
| public int FindNumberOfOccurences(string sentenceToScan, string characterToScanFor) | |
| { | |
| try | |
| { | |
| var stringToCheckAsCharacterArray = sentenceToScan.ToCharArray(); | |
| var characterToCheckFor = Char.Parse(characterToScanFor); | |
| var numberOfOccurenes = 0; | |
| for (var charIdx = 0; charIdx < stringToCheckAsCharacterArray.GetUpperBound(0); charIdx++) | |
| { | |
| if (stringToCheckAsCharacterArray[charIdx] == characterToCheckFor) | |
| { | |
| numberOfOccurenes++; | |
| } | |
| } | |
| return numberOfOccurenes; | |
| } | |
| catch | |
| { | |
| throw new ArgumentException(); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment