Wednesday, December 07, 2011 8:42 PM
from frederick.chapleau

560 days ago
Viewed 18 times
Revision 2

Tagged as wiki


Printer Friendly Version
PDF Version

Comments?


Token Replacement

Home / wiki / Token Replacement

Replace a list of field=value;field=value from the source string and return it.

 

public string ReplaceTokens(string tokenText, string content)
{
Dictionary<string, string> tokens = new Dictionary<string, string>();


// Split the token list to a list of unified key/value pair
List<string> splittedTokens = tokenText.Split(',').ToList();


// For each token, add it to the key/value pair
splittedTokens.ForEach(p => tokens.Add(p.Split('=')[0], p.Split('=')[1]));


// Replace the all found keys from the source, by the equivalent value
tokens.Keys.ToList().ForEach(key => content = content.Replace(key, tokens[key]));

return content;
}






google+