String.Format exception when format string contains “{“

At a guess, the html contains javascript or another source of braces ({ and }) which would all need doubling (to {{ and }}) to be usable with string.Format. I expect a different (more obvious) token may be in order, i.e. %%FILENAME%%. Then use either regex or string.Replace.

If you have a single tag, string.Replace is fine; if you have lots, there are tricks with regex and MatchEvaluator that may be helpful – like so but with a different regex pattern.


Update after the example html added: I would definitely use a different token; at the most basic level:

<param name="initParams" value="cc=true,markers=true,m=%%FILENAME%%" />

and

template = template.Replace("%%FILENAME%%", "video.wmv");

Leave a Comment