\documentclass{minimal} \usepackage{substr} \def\str{hellohello} \def\longstr{hellohellohellohello} \def\medstr{hellohellohello} \def\substr{ell} \def\subSTR{ELL} \newcounter{appearances} \begin{document} \bigskip{\bfseries IfSubStringInString} \IfSubStringInString{\substr}{\str}{``\subSTR'' is in ``\str''}{Error} \IfSubStringInString{\subSTR}{\str}{Error}{No ``\subSTR'' in ``\str''} \bigskip{\bfseries BeforeSubString and BehindSubString} Text befor ``\substr'' in ``\str'': \BeforeSubString{\substr}{\str} Text after ``\substr'' in ``\str'': \BehindSubString{\substr}{\str} \BeforeSubString{\substr}{\str}% \emph{\bfseries\substr}% \BehindSubString{\substr}{\str} \bigskip{\bfseries CountSubStrings} Count of ``\substr'' in ``\str'': \CountSubStrings{\substr}{\str} Count of ``\substr'' in ``\medstr'': \CountSubStrings{\substr}{\medstr} Count of ``\substr'' in ``\longstr'': \CountSubStrings{\substr}{\longstr} \bigskip{\bfseries SubStringsToCounter} \SubStringsToCounter{appearances}{\substr}{\str}% Count of ``\substr'' in \str'' (counter): \theappearances \end{document}