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){
                //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;
Re: Help with string parsing 80 80

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 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.