Ideally you should establish a convention for texts that need to be replaced, with some symbol or punctuation type for your file variables. For example, :{}
The following function may be useful for running the function:
using System.Text.RegularExpressions;
public static string TrocarTokens(string template, Dictionary<string, string> dicionarioVariaveis)
{
var rex = new Regex(@"\:{([^}]+)}");
return(rex.Replace(template, delegate(Match m)
{
string key = m.Groups[1].Value;
string rep = dicionarioVariaveis.ContainsKey(key)? dicionarioVariaveis[key] : m.Value;
return(rep);
}));
}
Template adapted:
Propriedade1: :{variavel_1}
Propriedade2: :{variavel_2}
...
Usage:
var dicionarioValores = new Dictionary<string, string>();
dicionarioValores["variavel_1"] = "Valor 1";
dicionarioValores["variavel_2"] = "Valor 2";
var saida = TrocarTokens(stringDoArquivo, dicionarioValores);
I got the idea from here .