Created
September 23, 2013 18:38
-
-
Save JamesBender/6674935 to your computer and use it in GitHub Desktop.
This file contains 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