Searching for a string in txt file with whitespace!

This is a discussion on Searching for a string in txt file with whitespace! within the C++ Programming forums, part of the General Programming Boards category; I'm trying to do this assignment which involves searching for all instances of a tag in one text file and ...

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    3

    Searching for a string in txt file with whitespace!

    I'm trying to do this assignment which involves searching for all instances of a tag in one text file and replacing all those tags with a word in another file. The text in the other file is currently:
    Code:
    [What?]	     thought
    I need to make a function that can skip past the beginning word and all the whitespace and then read and set "thought" to be equal to another string called "sub" (which I figure will use substr somehow). "thought" is just a simple example, I need it so that "sub" is equal to a single word length. EDIT: I checked and apparently it needs to work for multiple words. So instead if "thought" was "two words" I would need "sub" to be equal to "two words". Crap, that's even worse . "[What?]" is currently set as a string variable called "tag". "ss" is all the text from the replacement file. I was thinking I could subtract "tag" from "ss" and then set up a for-loop to skip past all the whitespace and start reading after that but I'm having a hell of a time getting my head wrapped around it. How would I get it to skip all the white space before and after the substitution string but still include the spaces between? How would I implement this?

    Code:
    void trim(string& ss)  // 
    {
    string sss = ss - tag;
    	size_t len = sss.length();
    	size_t lastPos, pos;
    	for (size_t i=0; i<len; ++i)  //No clue how to start this
    	{
               if (!isspace(sss[i]))
    	}
         sub = sss.substr(a, b) /// How do I get a and b?
    
    }
    Last edited by invisible_wall; 03-29-2009 at 10:41 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  2. Replies: 6
    Last Post: 01-03-2007, 02:02 PM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  4. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21