# 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
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.29905572533607483, "perplexity": 1982.3004283386754}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2015-22/segments/1432207929561.98/warc/CC-MAIN-20150521113209-00133-ip-10-180-206-219.ec2.internal.warc.gz"}