Skip to content

Instantly share code, notes, and snippets.

@JamesBender
Created September 20, 2013 13:03
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save JamesBender/6637162 to your computer and use it in GitHub Desktop.
using System;
namespace ThirtyDaysOfTDD.UnitTests
{
public class StringUtils
{
public int FindNumberOfOccurences(string sentenceToScan, string characterToScanFor)
{
throw new ArgumentException();
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