Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 12 down vote accepted
 \documentclass{minimal}
\usepackage{xstring}
\def\ReplaceStr#1{%
  \IfSubStr{#1}{XY}{%
    \StrSubstitute{#1}{XY}{$\to$}}{#1}}

\begin{document}

\ReplaceStr{aXYbXYc}

\ReplaceStr{abc}

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.