1
votes

How I can count characters in QByteArray, for example I have QByteArray and I want to know how many "*" in this array.

2
Can you guarantee each character will always be one byte in size? - cmannett85

2 Answers

2
votes

From QByteArray documentation:

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.

count.

0
votes

You could use QByteArray::indexOf(char ch, int from = 0) const inside a loop.

Maybe this:

int i = 0, counter = 0;

while((i = array.indexOf("*", i)) >= 0)
 counter++;