I would like to use C# .NET to replace every instance of text between dollar signs. For example:
Check out this TeX: $x\in\mathbb{Z}^+$. It's cool.
…becomes…
Check out this TeX: <img src="http://chart.googleapis.com/chart?cht=tx&chl=x\in\mathbb{Z}^%2B" alt="x\in\mathbb{Z}^+" />. It's cool.
Note that the formula needs to be URL encoded before it is passed to the Google Charts API.
Please could you show me how to do this using RegEx (or otherwise)?
You probably want to use the overload of
Regex.Replace, that accepts a delegate that computes the replacement:Your code in
GetCodeForTexmight be different (and you might think of a better name for it), but I’m sure you get the idea.Also, be careful with simple parsing using regexes like this. It means you can never use
$for anything else than enclosing TeX. And the result will be mess if you have unclosed$somewhere in the input text.