Skip to content

Instantly share code, notes, and snippets.

@JamesBender
Created September 23, 2013 18:38
Show Gist options
  • Save JamesBender/6674935 to your computer and use it in GitHub Desktop.
Save JamesBender/6674935 to your computer and use it in GitHub Desktop.
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