Skip to content

Instantly share code, notes, and snippets.

@rcurtis
Created March 11, 2015 19:58
Show Gist options
  • Save rcurtis/51304118bdc8c3f2f8c7 to your computer and use it in GitHub Desktop.
Save rcurtis/51304118bdc8c3f2f8c7 to your computer and use it in GitHub Desktop.
public static string Reverse(string input)
{
var builder = new StringBuilder(input.Length);
for (var i = input.Length - 1; i >= 0; i--)
{
builder.Append(input[i]);
}
return builder.ToString();
}
public static string CountOccurence(string input)
{
var bookKeeper = new Dictionary<char, int>();
foreach (var character in input)
{
if (bookKeeper.ContainsKey(character))
bookKeeper[character]++;
else
bookKeeper.Add(character, 1);
}
var builder = new StringBuilder();
foreach (var pair in bookKeeper)
{
builder.AppendFormat("{0}: {1}, ", pair.Key, pair.Value);
}
return builder.ToString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment