public int CountTokens()
{
int count = 0;
int delimiterCount = 0;
bool tokenFound = false;
int tmpPos = pos;
while (tmpPos < len) {
if (delim.IndexOf(str[tmpPos++]) >= 0) {
if (tokenFound) {
count++;
tokenFound = false;
}
delimiterCount++;
}
else {
tokenFound = true;
while (tmpPos < len
&& delim.IndexOf(str[tmpPos]) < 0)
++tmpPos;
}
}
if (tokenFound)
count++;
return retDelims ? count + delimiterCount : count;
}