Stripping <items in here> from a text file

This is a discussion on Stripping <items in here> from a text file within the C++ Programming forums, part of the General Programming Boards category; Stripping <items in here> from a text file what i wan to do is get rid of items in <items ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    114

    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 >

    Code:
     	CString file_string;
    	CString file_string_temp;
    	int start_index;
    	int end_index;
    	f.Read(file_string.GetBuffer(f.GetLength()),f.GetLength());
    
    	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
    Location
    If you knew I'd have to kill you
    Posts
    254
    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. http://www.dandongs.com/

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,823
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 01: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, 11:51 PM
  4. checking values in a text file
    By darfader in forum C Programming
    Replies: 2
    Last Post: 09-24-2003, 03: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

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