Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我如何计算 中的字符QByteArray,例如我有QByteArray并且我想知道这个数组中有多少个“*”。
QByteArray
从QByteArray 文档:
int QByteArray::count ( const char * str ) const This is an overloaded function. Returns the number of (potentially overlapping) occurrences of string str in the byte array.
数。
您可以QByteArray::indexOf(char ch, int from = 0) const在循环内使用。
QByteArray::indexOf(char ch, int from = 0) const
也许是这样:
int i = 0, counter = 0; while((i = array.indexOf("*", i)) >= 0) counter++;