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;
                }
            }

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.