The fact that both tests with
pdflatex return true is essentially a lucky coincidence.
xstring performs full expansion to the tokens in (some of) its arguments (see the package documentation); in the case of
\IfSubStr the first and second arguments are fully expanded.
What happens to
ß is actually two bytes in UTF-8;
- the first byte,
0xC3 makes TeX examine the next one,
0x9F and transform both according to an internal table to
utf8enc.dfu you find
- according to the current output encoding (here
\ss is transformed into
\T1\ss (a quite strange token) which is internally defined through
\chardef so it is unexpandable.
Thus you see that the same happens when you type
\ss, just jumping over some of the above steps.
lualatex is used,
ß undergoes no expansion at all, because
lualatex directly reads UTF-8 and internally transforms it into (abstract) Unicode. On the other hand,
\TU\ss (similar to the above), which is essentially equivalent to type
\char`ß (so it's not the same as typing
pdflatex and you'll get a low level error
! Illegal parameter number in definition of \@xs@arg@ii.
<to be read again>
No error with
There's no guarantee of success when
\IfSubStr is used for non ASCII characters.