A ce moment les Regex peuvent répondre au problème. Il faut utiliser la méthode Regex.Replace avec la surcharge qui attend un MatchEvaluator
Code:
1 2 3 4 5 6 7 8 9 10 11 12
| static void Main(string[] args)
{
string input = "{var1} - {var2} , un bout de texte;";
string final = Regex.Replace(input, "{var[0-9]+?}",
delegate(Match match)
{
return GetValueFromVar(match.Value);
}
);
Console.ReadLine();
} |
La méthode GetValueFromVar doit retourner la chaîne de caractères correspondant à tes variables ({var1}, {var2}, ...)