text "variables"

P

Peter

Hi

sorry, this doesn't really have anything to do with c#, but I wasn't
sure where else to post.

I am writing some code which needs to parse some text (a string) which
is to contain "variables" (special tags) which should be replaced with
real values.

For example, a variable called "CURRENT_DATE" or "USER_NAME".

Is there any standard or best-practice for the syntax for this sort of
thing?

Like "As of today {%CURRENT_DATE%} your username {%USER_NAME%} is
suspended..."


Thanks,
Peter


--
 
P

Peter Morris

I did something similar for generating email messages from a website. I
just did something like this


string RenderMessage(string viewName, Dictionary<string, string> values)
{
string text = (load it from file using viewName);
foreach(KeyValuePair<string, string> kvp in values)
text = text.Replace("{%" + kvp.Key + "%}", kvp.Value);
return text;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top