ignoring

closed account (4w7X92yv)
Hello

I got this code witch takes the 8 first bits a a string and let ingores certain letters (in this case 'f')

1
2
3
while((count99 < 8) && (offset99 < code.size())){
if(code[offset99] != 'f'){
Latitude.push_back(code[offset99]);


but now i want to change it so it ignores 'ffffff'

1
2
3
while((count99 < 8) && (offset99 < code.size())){
if(code[offset99] != 'ffffff'){
Latitude.push_back(code[offset99]);


how can i do this?

Best Regards
Joriek
"fffff" is a string in itself, so you'd have to make sure that 6 consecutive chars of the string are not equal to f. One way to do this would be to see if a char is 'f', and if it is, check the next one for 'f'. Keep doing this until you either don't find an 'f', or find six:

1
2
3
4
5
6
7
8
9
for(unsigned i = 0; i < string.size(); ++i)
{
if(string[i] == 'f')
{
int count = 0;
while(string[++i] == 'f'&&count < 6){count++;}
if(count == 6){IGNORE();}
}
}
There is a bit of trouble with that test you have there. When you enter the inner while loop, you stop comparing against the size of the string and so are free to run outside its bounds.

I'd just add one to count if you find an 'f', and reset it to 0 if you find anything else.
'Tis be true. Count should have also been initialized to one... How embarrassing. But your technique is much more efficient anyway.
Topic archived. No new replies allowed.