# Replacing a substring

I've got a string like this: aXYbXYc, and need to replace the XY substring with a right arrow: a $\to$ b $\to$ c.

Is there any function (also provided by external packages) to help me do that?

-

\documentclass{minimal}
\usepackage{xstring}
\def\ReplaceStr#1{%
\IfSubStr{#1}{XY}{%
\StrSubstitute{#1}{XY}{$\to$}}{#1}}

\begin{document}

\ReplaceStr{aXYbXYc}

\ReplaceStr{abc}

\end{document}
-
This is exactly what I was looking for, thanks! –  peoro Jan 10 '11 at 14:29