-
August 10th, 2010, 09:23 AM
#1
HELP: pair-value search & replace
Does anyone know to quickly make a multiple search & replace app (in either C or C++)? Am not interested in searching multiple files, just one file. I want to translate a list of unicode characters into something else (pair-value lookup table) ... so it's basically a crude/naive translator!
I just need a quick pseudocode to get me started. Or maybe there's an opensource/free code already written?
PS: Or maybe it's easier quicker with sed/awk/perl?
-
August 10th, 2010, 09:51 AM
#2
Re: HELP: pair-value search & replace
1) Read the entire file into a single std::string.
2) Use std::string::find_first_of() repeatedly to find the next substring of interest.
3) Copy the intermediate portion of the string to another std::string (output).
4) Pull the relevant replacement substring from a std::map<std::string,std::string>.
5) Concatenate the replacement substring onto the output string.
6) Go to 2 until done.
7) Write the output string back to a file.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|