public string FormatVars(string text) { Regex r = new Regex("~(.+?)~"); //text = r.Replace(text, "{0}"); MatchCollection mC = r.Matches(text); for (int i = 0; i < mC.Count; i++) text = text.Replace(mC[i].ToString(), "{i}"); return text; }