I want to do something like this, I have a dictionary with keys and values, and a text file like this:
Hello my name is $(Name) and my favorite movie is $(Movie).
I want to read in the file and replace the occurrences of $(…) based on the values in the dictionary, so in this case the dictionary would have a key for Name and Movie.
How would I go about doing this? If I parsed through each word, what would be the regular expression to match $(AnyWord), or would it be better to do something like this:
foreach(var word in file)
{
if (word.length > 3)
{
if (word.substring(0,2)=="$(" && word.substring(word.length-1)==")")
Lookup word in dictionary
}
}
Thanks
Use a MatchEvaluator to do the replacements:
If there are any syntax errors I apologize. I’m at work at the moment with no C# compiler so I’ll have to fix them when I get home.