# xstring character comparison and \meaning

\documentclass[pdftex,a4paper,12pt,oneside]{book}%

\usepackage{xstring}

\begin{document}

\newcommand{\tmpa}{}
\newcommand{\tmpb}{}
\newcommand{\tmpc}{}

\renewcommand{\tmpc}{abcdefg} \noindent tmpc: \tmpc \\
\renewcommand{\tmpa}{\meaning\tmpc} tmpa: \tmpa \\
len: \StrLen{\tmpa} \\
char(20): \StrChar{\tmpa}{20}[\tmpb] \tmpb \\
pos(f): \StrPosition{\tmpa}{f}

\end{document}


Result:

tmpc: abcdefg

tmpa: \long macro:->abcdefg

len: 21

char(20): f

pos(f): 0


Why? tmpa obviously contains character 'f' on the position of 20 as we can find it with \StrChar. But that 'f' not the same as the one we are trying to find with StrPos. I thought about catcode differences, but did not find anything usable (I might be wrong with changing catcode of 'f' before searching for it).

-

\meaning\tmpc produces a string where all characters have category code 12 (but spaces have category code 10). When you compare the strings, the category code 11 f is not found.
The working of \StrPosition uses delimited argument macros and the delimiter must be the same both for character code and category code.
Indeed, if you say \StrPosition{\tmpa}{\string f} the printed result is 20 (\StrPosition does complete expansion).
the use of \string f is clear but how can I use \string before a macro? e.g. \string\mymacro results in "\mymacro" – pmks Apr 16 '12 at 7:42
I store data using \markright (counter value and sectionname) and try to get them back using \StrBetween{\firstmark}{{\delim}{\delim} but with package babel \firstmark is full of macros and \StrBetween can not cope with them. So I use \StrBetween{\meaning\firstmark}... and decently get my values. With accented chars and inputenc I get coded strings like this in my output:\IeC {\’\i }\’a\H o\’o\"u\"o. I thought that it might help to change (’) to (') and I used \StrSubstitute and run into this problem. After all, now I can change normal chars but no (’) :( – pmks Apr 16 '12 at 13:51