![]() |
Re: file overwrite data manipulation
"Lans Redmond" <lredmond@nyc.rr.com> wrote in message news:pWuKa.6447$DF1.2587377@twister.nyc.rr.com... > try looking at strtok function. > it will parse ur string based on the delimiter you pass in (tilde), your > parsed string will be the value, after the 5th token then just do a memmove > to change the data > > Please don't top post! You have to be aware that using strtok might result in some unwanted side-effects because of its design. Before using it one should consider that it holds its data in a static buffer which means that you can't use strtok in two places at the same time, you're in trouble with multithreading, it modifies the input sequence(!!!), it depends on reading lines, which means that you have to introduce buffers big enough for the longest line and this might lead to a waste of buffersize. Thus it might be better to use some other tokenizer approach using istreambuf_iterators or whatever. A simple tokenizer could look like this: //////////////////////////////////////////////////////////////////////////// // std::vector<std::string> TokenizeString( const std::string& Text, const std::string& Delimiters ) // Tokenize a passed string with respect to the provided delimiters // // e.g. // string Line = "this_dog_is mine"; // string Delimiters = " ,:_;#"; // vector<string> WordList = TokenizeString( Line, Delimiters ); //////////////////////////////////////////////////////////////////////////// // { std::vector<std::string> WordList; std::string::size_type Begin, End; std::string Word; Begin = Text.find_first_not_of( Delimiters ); // skip blanks or whatever one finds at the beginning while( Begin != std::string::npos ) { End = Text.find_first_of( Delimiters, Begin ); if( End == std::string::npos ) { // we'v reached the end without finding another delimiter End = Text.length(); } Word.assign( Text.begin() + Begin, Text.begin() + End ); WordList.push_back( Word ); Begin = Text.find_first_not_of( Delimiters, End); } return WordList; } Regards Chris |
| All times are GMT. The time now is 11:35 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.