Int_t TString::CountChar(Int_t c)

Hi,
I found the following function in TString :

Int_t TString::CountChar(Int_t c)
// Return number of times character c occurs in the string.

It seems a bit odd the character ‘c’ is an integer…
Bye, Zesp

This analagous to fputc() et al in the stdio.h library (see man fputc).

Cheers, Fons.

I don’t really see the point…
From the comment in this function, I would have expected something like:

Int_t CountChar (Char_t c)  
{   
   Int_t count = 0 ;
   for (Int_t i=0; i<this.Length(); i++) { if ( this[i] == TString(c) ) count++ ; }
   return ( count ) ;
}

i.e. what I’m using.
Cheers, Z

Of course TString::CountChar() uses directly the TString internals and hence is much more efficient then using TString::operator[] and using TString() ctor. The argument being Int_t or char is transparent due to the automatic type promotion.

Cheers, Fons.

Ok ! I did use it in a bad way.
Thanks :smiley:
Z