# Check if a string contains a given character

I want to implement an if-then-else depending on whether the argument contains a special character or not. Should I be looking here: http://www.tug.org/TUGboat/Articles/tb28-1/tb88glister.pdf, or does anyone know a simpler way?

-

\documentclass{article}
\usepackage{xstring}
\begin{document}

\IfSubStr{Rotterdam}{otter}{ true }{ false }

\end{document}

-
\makeatletter
\def\instring#1#2{TT\fi\begingroup
\edef\x{\endgroup\noexpand\in@{#1}{#2}}\x\ifin@}
\makeatother

\def\mystring{abcdef}

\if\instring{a}{abcdef}\message{YES}\else\message{NO}\fi
\if\instring{a}{\mystring}\message{YES}\else\message{NO}\fi


LaTeX should show "YES" in both cases. However, it depends on the kind of "special character" you are interested in.

-
The specific character was "=". This works great, thanks! I was actually just around the corner from a similar solution, all thanks to tex.ac.uk/tex-archive/info/macros2e/macros2e.pdf, but the guide isn't so clear around what an "\ifin@ switch" is, do you happen to have a good guide to doing "advanced" stuff like this? – oleks Aug 29 '11 at 15:30
Nice. I didn't know about \in@ and \ifin@ ... – clemens May 25 '13 at 11:05
@cgnieder They're well hidden in the LaTeX kernel. ;-) Of course expl3 makes better tools available. – egreg May 25 '13 at 11:07