CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2009

    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?

  2. #2
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Seattle, WA

    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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.