Implement StrintCount utility

Counts the number or delimiters found in a given string
This commit is contained in:
Kawe Mazidjatari 2022-09-22 17:08:20 +02:00
parent 4cda4371cb
commit de2400f6a2
2 changed files with 16 additions and 0 deletions

View File

@ -640,6 +640,21 @@ string StringUnescape(const string& svInput)
return result;
}
///////////////////////////////////////////////////////////////////////////////
// For counting the number of delimiters in a given string.
size_t StringCount(const string& svInput, char cDelim)
{
size_t result = 0;
for (size_t i = 0; i < svInput.size(); i++)
{
if (svInput[i] == cDelim)
{
result++;
}
}
return result;
}
///////////////////////////////////////////////////////////////////////////////
// For splitting a string into substrings by delimiter.
vector<string> StringSplit(string svInput, char cDelim, size_t nMax)

View File

@ -48,6 +48,7 @@ bool StringReplace(string& svInput, const string& svFrom, const string& svTo);
string StringReplaceC(const string& svInput, const string& svFrom, const string& svTo);
string StringEscape(const string& svInput);
string StringUnescape(const string& svInput);
size_t StringCount(const string& svInput, char cDelim);
vector<string> StringSplit(string svInput, char cDelim, size_t nMax = SIZE_MAX);
/////////////////////////////////////////////////////////////////////////////