Find characters in a string

Hi all,

I already checked http://www.cplusplus.com/reference/string/string/ and didn't find what I'm looking for, but I thought I'd ask anyways: is there any function in the string class that finds how many of a certain character there are in a string? If there isn't, the only way I could think of doing this would be to use string::find(), then string::erase(), and put this in a for loop, and that would be a pain...
This is very simple to implement yourself. Something like:

1
2
3
4
5
6
7
8
9
10
11
12
int findCharInString (std::string input, char charToFind)
{
  int total = 0;
  for (int i=0; i<input.length(); ++i)
  {
    if (input[i] == charToFind)
    {
       ++total;
     }
    }
  return total;
}
Topic archived. No new replies allowed.