Reputation: 557
I have QByteArray and need to remove first 4 lines. I can do it with regular expressions, for example, but is it some easier way?
UPD: first lines(more than 4) in my QByteArray is text, with '\n' in the end.
Upvotes: 0
Views: 1882
Reputation: 2374
What about searching the fourth occurrence of '\n' (using int QByteArray::indexOf ( char ch, int from = 0 ) const) and then removing the bytes up to that position (using QByteArray & QByteArray::remove ( int pos, int len ))?
Edit: Not tested, but something along these lines:
QByteArray ba("first\nsecond\nthird\nfourth\nfifth");
size_t index = 0;
unsigned occur = 0;
while ((index = ba.indexOf('\n', index)) >= 0){
++occur;
if (occur == 4){
break;
}
}
if (occur == 4){
ba.remove(0, index + 1);
}
Upvotes: 2