0

I am trying to parse a text file with 1200 songs. I want to increase the barcount every time I come across a '|' or a ']' character. I want to have a new line every time the barCount is equal to 4. However, if I come across '\n' I want to reset the bar count to 0.

Unfortunately, what I have so far is only counting '|' and inserting a new line. Can anyone help me fix my code?

This is some of what I have tried to do:

while((start = chartDataString.find(" |", start)) != string::npos){
                barCount++;
                start+=2;
                charCount++;
                if(chartDataString[charCount]==']'){barCount++;}
                //each line should be 80 characters long
                //if(barCount == 3){//  || chartDataString.find("]")){
                if(chartDataString.find("\n") !=string::npos){
                    barCount = 0;
                }
                if(barCount == 4 || chartDataString[charCount] == ']') {
                    //cout<<"Number of bars: "<<barCount<<endl;
                    chartDataString.insert(start, "\n");
                    barCount = 0;
                    charCount= 0;
                }
            }
2
Contributors
1
Reply
18
Views
3 Years
Discussion Span
Last Post by Ancient Dragon
0

Call find_first_of() instead of just find(), as in the example in this thread. In a while loop keep calling find_first_of() until it returns npos. Each time one of the characters is found replace it with something else, such as a space.

Edited by Ancient Dragon

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.