writing a Find and replace program

How do I go about writing my own find and replace program? I want to clean_up a file that has too many returns, tabs, dashes, and extra spaces. Also, I want to replace tabs, dashes, space with any character of my choice, including non-printing characters.
use destructor to clean up your stack, and you cannot over load all the operators just specific ones.
here is the destructor implementation, (note that you do not need to call it)

1
2
3
4
5
6
CRectangle::~CRectangle () 
{
  cout<<"destructor called\n";
  delete width;
  delete height;
}
Thanks, however I'm not sure I understand just how to use that. Lets say that I have a space, a tab, and a lot of words that extends to more than one line that I wish to cleanup. How would I use
1
2
3
4
5
6
CRectangle::~CRectangle () 
{
  cout<<"destructor called\n";
  delete width;
  delete height;
}

to delete each of them separately? Also, how could I insert a carriage return?
I don't think Eyad's answer has anything to do with the question asked.

To read from a file you can use std::ifstream.

To write to a file you can use std::ofstream.

You should probably avoid reading and writing from the same file at the same time.
Peter87, I thank you for your effort. However I already know how to read and write to/from files. Reading/writing has nothing to do with the point of my question. The point of my question is "Find/Replace" and "Find/Insert". I have a file with too much white space, too many tabs, too dashes, and far too many words that I want to *Find* and *Replace* with a *Space*. I wish to download a file from the web and have a program/macro reorganize the data, deleting the tabs, the extra spaces, and the words, leaving just organized numbers in the file, all done automatically. My problem is that I do not know the codes for such action, and I haven't been able to find anything on_line that will teach me to write my own *Find/Replace* program. I know that Microsoft Word has a good one, although it is incomplete.
You already know how to read the file. So read in the entire file. Once the file is in memory, find only one of the things you've mentioned you want to replace. For example, make it work for finding tabs only, and replace them with whatever you want. Once you've got that working, add in the others.

If you want this to be configurable depending on file types, create your own file, lets call it config, that has all the replace keywords you want to replace, then at any given run you can add/remove from YOUR list, which will be read in first (and not hardcoded), then parse the other file.
Wow! Thanks, now I'll try to understand what's it saying.

 
Once the file is in memory, find only one of the things you've mentioned you want to replace. 

I don't know the code for a space, a tab, a dash, or a carriage return. Where could I find a list of these codes?
1
2
3
4
If you want this to be configurable depending on file types, create your own file,
 lets call it config, that has all the replace keywords you want to replace, then at 
any given run you can add/remove from YOUR list, which will be read in first (and
 not hardcoded), then parse the other file.

The file that will be downloaded is in HTML format. What I wish to delete will never change. I want this to be all automatic when the file is downloaded. I really appreciate your help, thanks!
http://bit.ly/IH40w6

This doesn't handle all your cases, but will handle most.
1
2
3
4
void replace_chartype(string &line, char type)
{
	replace(line.begin(), line.end(), type, ' ');
}


You can figure out the rest. =P
Last edited on
I don't know the code for a space, a tab, a dash, or a carriage return. Where could I find a list of these codes?


http://www.cplusplus.com/reference/clibrary/cctype/isspace/

And of course, you have dash on your keyboard: '-'

Learning to google is advisable.
Thanks all for your help. Now I have a beginning.
Topic archived. No new replies allowed.