Also you call input.IndexOf(c, charcheck);. I'm not 100% sure what the complexity of string.IndexOf is in C# but it's going to be related to the length of the string in some way - the naive implementation would be O(n*m) (m == 1 as you're searching 1 char at a time) worst case. Update: speculation confirmed by http://stackoverflow.com/a/2584204/1402923https://stackoverflow.com/a/2584204/1402923