Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Search and Replace Program

This topic is 5299 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I recently made a Search and Replace program, that is suppose to do multiple searches and replaces on lots of files ..like 1000 different files... how i made it work, is it loads the whole file (.htm) into a std::string, then it does the S&R on the string...deletes the old file, and re writes the string to a new file, making the search and replace complete.. the problem with this is that the files I would be doing this on are rather importantant, and this way just doesn''t seem safe enough to use really, especially when i have to delete the whole file and re-write the whole file just to replace maybe one word..and some of the files, are near 50K in size.. Can somone tell me a better way to do a massive search and replace? or just a search and replace in a file, without having to delete it, then re-write it? thanks alot kag1

Share this post

Link to post
Share on other sites
There shouldn''t be any problem loading 50k into memory. I''d probably use something other than std::string though, ''plain'' memory should be better. Unless some of the functions std::string provides are essential for your s&r algo.

Since you say that the file is important and you don''t want to mess it up, why not make a backup instead of deleting it?

- read file content
- move file to ''file.bak''
- do s&r
- write file content (to new file)

For complex s&r I''d advise you to take a look at ''regular expressions'' (I think ''boost'' provides a regular expression class that you could use). They can be a powerfull tool if you know how to use them.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!