Rewritten as minimum non-working example:
\documentclass{article}
\makeatletter
\usepackage{xstring}
\usepackage{xparse}
\newcommand\textfromcase[1]{%
\IfEqCase{#1}{% for the purposes of this example:
{0}{AB} % \textfromcase[0] expands to AB
{1}{CD} % \textfromcase[1] expands to CD
% and many more lines of this kind.
}}
\newcommand{\EscSubstitute}[2]{\expandafter\StrSubstitute\expandafter{\x}{#1}{#2}[\x]}
\newcommand\substitute[1]{{%
\noexpandarg% because I otherwise get weird error messages.
\StrSubstitute{#1}{BC}{CB}[\x]% replacements for example.
\EscSubstitute{PQ}{QP}% many more lines of this kind.
\x}}
\newcommand{\concatenate}[1]{%
\substitute{\@for \el:=#1\do{\textfromcase{\el}}}%
}
\makeatother
\begin{document}
\substitute{ABCD} = ACBD.
\concatenate{1,0} = CDAB.
\concatenate{0,1} $\neq$ ACBD!
\end{document}
\concatenate{0,1}
should expand to ACBD
but instead expands to ABCD
.
\substitute
but you've deliberately disabled much the same idea for\StrSubstitute
using\noexpandarg
. That makes me suspect there is more to the arguments here than simple text. Can you give more detail? Also, at present we have to guess what packages you are using: a full minimal working example (MWE) would be useful.expl3
, by the way.\noexpandarg
is because it gives me weird error messages otherwise. I tried usingexpl3
, but couldn't get it done that way, either.\@for
part. That explains why you've used\noexpandarg
so I can hopefully provide a solution.\@for
was from my in-between attempts at finding another solution. With the\@for
, the error message on leaving out the\noexpandarg
is different, but in either case there is an error.