Thread: Stripping <items in here> from a text file

  1. #1
    Registered User
    Join Date
    Mar 2004

    Stripping <items in here> from a text file

    Stripping <items in here> from a text file

    what i wan to do is get rid of items in <items in here>
    for example, for the string "dsafgsgwrgh<itema>grsgwrhhwr<itemb>fsdf"

    i want to get rid of "itema" and "itemb"
    here is my code
    - open file
    - copy file to a CString
    - look for <
    - look for >

     	CString file_string;
    	CString file_string_temp;
    	int start_index;
    	int end_index;
    	start_index = file_string.Find("<");
    	end_index = file_string.Find(">");
    	file_string_temp = file_string.Left(start_index);
    	int aaa = file_string.GetLength();
    	int b=5;
    but unfortunately it doesnt work
    is the file too big? the file is about 2,000,000,000 in f.GetLength
    file_string.Left(start_index); copies the entire file_string instead of only copying left strings

    can somebody tell me what's wrong?

  2. #2
    Amazingly beautiful user.
    Join Date
    Jul 2005
    If you knew I'd have to kill you
    Unless GetLength isn't what I think it is, your file is 2 GB, so yes, it's probably too big. Try reading the file in chunks and processing them. You'll just have to be careful about an "<Item>" split across two chunks. Also, do a check to see what "start_index" and "end_index" are printing out.

    You might want to loop from start_index to end_index and copy it into another string, instead of doing the "left" thing, because copying a large portion of an already gigantic string will be a slow operation.
    Programming Your Mom.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Why do you even need to store any of the file?

    Read in a character
    Examine the character and the current state of your state machine
    Then decide how to update the state machine, and whether to write out a character.
    Rinse and repeat until the end of the file.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  2. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  3. Simple File encryption
    By caroundw5h in forum C Programming
    Replies: 2
    Last Post: 10-13-2004, 10:51 PM
  4. checking values in a text file
    By darfader in forum C Programming
    Replies: 2
    Last Post: 09-24-2003, 02:13 AM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 03:58 PM