I believe that I found a way to remove extra spaces from a text file,
as follows: 

for (int x = 1; x <= index; x++)
        {
                pos1 = 0, pos2 = 0; //reset the position variables for a new 
loop
                
                //find function return the unsigned int string::npos if 
substring
not found
                //avoid repetition of the loop

                while (page[x][x].find("  ",pos2) != string::npos) 
                {
                        pos1=page[x][x].find("  ",pos2);
                        cout << "POS1 : " << pos1 << " POS2: " << pos2 << "  ";
                        page[x][x].erase(pos1,1);
                        pos2=pos2+pos1;
                }
        }
but it only removes in wherein there are two or three spaces, above
that it does not work. 

--- In [email protected], "Pedro von Wald" <[EMAIL PROTECTED]> wrote:
>
> --- In [email protected], Mickey Mathieson <user14312@> wrote:
> >
> > 
> > --- Pedro von Wald <lzwald@> wrote:
> > 
> > > I am working on the school proj, but I am having
> > > some difficult in
> > > processing the text file.
> > > Basically I am using the following to process the
> > > content of the file
> > > once it is copied to a mult. array (page[i][i]).
> > > 
> > > for (int x = 0; x <= page[1][1].size(); x++)
> > >     {
> > > 
> > >      
> > >
> > names[x][x]=page[1][1].substr(names[x][x].size(),page[1][1].find("
> > > ",names[x][x].size()));
> > >       cout << " TESTING 2: " << names[x][x] << "
> > > SIZE: " <<
> > > names[x][x].size();
> > >     }
> > > 
> > > where page is a mult. array that contains the file
> > > as a whole, and
> > > name is a mult array that is supposed to obtain each
> > > individual word
> > > inside the file. The problem is that the file has
> > > multiple spaces
> > > between the words and at the end of lines, besides
> > > it also contains
> > > "carriage returns" .
> > > 
> > > The whole code can retrieved at: 
> > > http://rafb.net/p/e8phJy32.html
> > > 
> > > thanks for any help,
> > > -pedro
> > > 
> > > 
> > > 
> > 
> > You can filter out the unnecessary control characters
> > etc. in your first loop before filling the Page array.
> > 
> > 
> 
> I am trying to do that, basically 
> My problem is to filter down all the extra spaces between characters.
> Like in a text file I could have a sequence like:
> "word1 word2 word3   word5  word6 word7 word8   word9" I have to
> remove all the extra spaces so that there would be only one space
> between each character and  that would make it easy to collect each
> word individually to a different array which would contain the words
> as individual entities. The carriage returns are not a problem because
> I copied each line of the string content (which contains the whole
> file) to individual arrays. Now I just have to remove the extra space
> inside each line of the individual arrais, so that I can collect the
> words indivually for a different array. Any suggestion to remove such
> extra space would cool, I will try some sort of algorithm to see how
> it goes. 
> thanks!
> -pedro
> 
> > 
> > Mickey M.
> > Construction Partner Inc.
> > http://www.constructionpartner.com
> > 
> > __________________________________________________
> > Do You Yahoo!?
> > Tired of spam?  Yahoo! Mail has the best spam protection around 
> > http://mail.yahoo.com
> >
>


Reply via email to