Created
September 19, 2013 20:48
-
-
Save JamesBender/6629630 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) | |
{ | |
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; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment