Some years ago I wrote a routine \UD@KeepKthOfLArguments which lets you choose an arbitrary undelimited argument from an arbitrary amount of undelimited arguments which—due to recursion—is not bound to the 9-argument-limit usually imposed on TeX' macro-programming.
Unfortunately \IfStrEqCase itself is not fully expandable and therefore cannot be used within \UD@KeepKthOfLArguments's first argument for evaluating the number K.
Thus you have to do it the other way, i.e., call \UD@KeepKthOfLArguments from within \IfStrEqCase for selecting one of three arguments:
\documentclass{article}
\usepackage{xstring}
\makeatletter
%%=========================================================================
%% Paraphernalia:
%% \UD@firstoftwo, \UD@secondoftwo, \UD@PassFirstToSecond
%%.........................................................................
\newcommand\UD@firstoftwo[2]{#1}%
\newcommand\UD@secondoftwo[2]{#2}%
\newcommand\UD@PassFirstToSecond[2]{#2{#1}}%
%%-------------------------------------------------------------------------
%% Check whether argument is empty:
%%.........................................................................
%% \UD@CheckWhetherNull{<Argument which is to be checked>}%
%% {<Tokens to be delivered in case that argument
%% which is to be checked is empty>}%
%% {<Tokens to be delivered in case that argument
%% which is to be checked is not empty>}%
%%
%% The gist of this macro comes from Robert R. Schneck's \ifempty-macro:
%% <https://groups.google.com/forum/#!original/comp.text.tex/kuOEIQIrElc/lUg37FmhA74J>
%%
%% A concern in his posting is that the argument is hit with \string
%% after some expansions which in edge cases might result in unbalancing
%% surrounding \if..\fi-constructs if the macro is used inside of such
%% \if..\fi-constructs.
%%
%% That challenging concern sickened me. ;-)
%%
%% Therefore I decided to implerment a variant where this cannot happen
%% as expansion is forced by \romannumeral:
%%
%% After the first expansion-step, \string is not applied yet.
%% After the second expansion-step, any possibly disturbing remainders
%% are already removed due to \romannumeral-expansion.
%%
%% No eTeX- or whatsoever extensions. No \if.. .Only \romannumeral,
%% digit 0, space token for terminating \romannumeral-expansion,
%% \string, \expandafter, \UD@firstoftwo, \UD@secondoftwo, {, }.
%%
%% May 20, 2016
%%
%% Ulrich Diez (e-mail: ud.usenetcorrespondence@web.de)
%%
\newcommand\UD@CheckWhetherNull[1]{%
\romannumeral0\expandafter\UD@secondoftwo\string{\expandafter
\UD@secondoftwo\expandafter{\expandafter{\string#1}\expandafter
\UD@secondoftwo\string}\expandafter\UD@firstoftwo\expandafter{\expandafter
\UD@secondoftwo\string}\expandafter\expandafter\UD@firstoftwo{ }{}%
\UD@secondoftwo}{\expandafter\expandafter\UD@firstoftwo{ }{}\UD@firstoftwo}%
}%
%%-------------------------------------------------------------------------
%% Keep only the K-th of L consecutive undelimited arguments.
%% ( IF K < 1 OR K > L just remove L consecutive undelimited arguments. )
%%.........................................................................
%% \UD@KeepKthOfLArguments{<integer number K>}%
%% {<integer number L>}%
%% {<Tokens to insert before K-th argument>}%
%% <L consecutive undelimited arguments>
%%
%% If K >= 1 and K <= L yields:
%% <Tokens to insert before K-th argument><K-th undelimited argument>
%% If K < 1 or K > L
%% (-> there is no K-th argument in the set
%% of <L consecutive undelimited arguments> )
%% yields:
%% <Tokens to insert before K-th argument>
%%
%% Examples:
%%
%% X\UD@KeepKthOfLArguments{3}{7}{<Tokens to insert>}{A}{B}{C}{D}{E}{F}{G}X
%% yields: X<Tokens to insert>CX
%%
%% X\UD@KeepKthOfLArguments{5}{2}{<Tokens to insert>}{A}{B}X
%% yields X<Tokens to insert>X
%%
%% X\UD@KeepKthOfLArguments{0}{2}{<Tokens to insert>}{A}{B}X
%% yields X<Tokens to insert>X
%%
%% X\romannumeral0%
%% \UD@KeepKthOfLArguments{3}{7}{ <Tokens to insert>}{A}{B}{C}{D}{E}{F}{G}X
%% yields: X\romannumeral0 <Tokens to insert>CX
%% yields: X<Tokens to insert>CX
%% In case of embedding the whole thing in other expansion-contexts,
%% you need to have "hit" \romannumeral by only one \expandafter-chain for
%% obtaining the result...
%%
%% January 17, 2005
%%
%% Ulrich Diez (e-mail: ud.usenetcorrespondence@web.de)
%%
\newcommand\UD@KeepKthOfLArguments[2]{%
\expandafter\UD@KeepKthOfLArgumentsA
\expandafter{\romannumeral\number\number#1 000\expandafter}%
\expandafter{\romannumeral\number\number#2 000}%
}%
\newcommand\UD@KeepKthOfLArgumentsA[3]{%
\UD@CheckWhetherNull{#1}{%
\UD@RemoveNArguments{#2}{#3}{}%
}{%
\expandafter\UD@PassFirstToSecond
\expandafter{%
\UD@firstoftwo{}#1}{\UD@KeepKthOfLArgumentsB{#1}{#2}}{#2}{#3}%
}%
}%
\newcommand\UD@KeepKthOfLArgumentsB[5]{%
\UD@CheckWhetherNull{#1}{%
\UD@RemoveNArguments{#3}{\UD@RemoveNArguments{#2}{#5}}{}%
}{%
\UD@CheckWhetherNull{#2}{%
\UD@RemoveNArguments{#4}{#5}{}%
}{%
\expandafter\UD@PassFirstToSecond
\expandafter{%
\UD@firstoftwo{}#2}{\expandafter\UD@KeepKthOfLArgumentsB
\expandafter{%
\UD@firstoftwo{}#1}}{#3}{#4}{#5}%
}%
}%
}%
\newcommand\UD@RemoveNArguments[3]{%
\UD@CheckWhetherNull{#1}{#2#3}{%
\UD@firstoftwo{%
\expandafter\UD@RemoveNArguments
\expandafter{\UD@firstoftwo{}#1}{#2}{#3}%
}%
}%
}%
%----------------------------------------------------------------------------
%----------------------------------------------------------------------------
\newcommand*{\ConditionalTextDesired}[1]{%
% \IfStrEqCase will deliver the call to \UD@KeepKthOfLArguments plus
% \UD@KeepKthOfLArguments's first argument:
\IfStrEqCase{#1}{%
{case 1}{\UD@KeepKthOfLArguments{1}}%
{case 2}{\UD@KeepKthOfLArguments{2}}%
{case 3}{\UD@KeepKthOfLArguments{1}}%
{case 4}{\UD@KeepKthOfLArguments{1}}%
{case 5}{\UD@KeepKthOfLArguments{2}}%
}[{\UD@KeepKthOfLArguments{3}}]%
% Here come the remaining arguments of \UD@KeepKthOfLArguments:
{3}{}%
{some long text which is identical for case 1, case 3 and case 4.}%
{other text for case 2 and case 5.}%
{Error: Unknown parameter ``#1'' to ConditionalText.}%
}%
\makeatother
\begin{document}
\par\ConditionalTextDesired{case 1}
\par\ConditionalTextDesired{case 2}
\par\ConditionalTextDesired{case 3}
\par\ConditionalTextDesired{case 4}
\par\ConditionalTextDesired{case 5}
\end{document}
By the way: In case you wish to do such choosing within pure-expansion-contexts, here is an example of a strategy based on using delimited arguments:
\documentclass{article}
\makeatletter
%%=========================================================================
%% Paraphernalia:
%% \UD@firstoftwo, \UD@secondoftwo, \UD@PassFirstToSecond
%%.........................................................................
\newcommand\UD@firstoftwo[2]{#1}%
\newcommand\UD@secondoftwo[2]{#2}%
\newcommand\UD@PassFirstToSecond[2]{#2{#1}}%
%%-------------------------------------------------------------------------
%% Check whether argument is empty:
%%.........................................................................
%% \UD@CheckWhetherNull{<Argument which is to be checked>}%
%% {<Tokens to be delivered in case that argument
%% which is to be checked is empty>}%
%% {<Tokens to be delivered in case that argument
%% which is to be checked is not empty>}%
%%
%% The gist of this macro comes from Robert R. Schneck's \ifempty-macro:
%% <https://groups.google.com/forum/#!original/comp.text.tex/kuOEIQIrElc/lUg37FmhA74J>
%%
%% A concern in his posting is that the argument is hit with \string
%% after some expansions which in edge cases might result in unbalancing
%% surrounding \if..\fi-constructs if the macro is used inside of such
%% \if..\fi-constructs.
%%
%% That challenging concern sickened me. ;-)
%%
%% Therefore I decided to implerment a variant where this cannot happen
%% as expansion is forced by \romannumeral:
%%
%% After the first expansion-step, \string is not applied yet.
%% After the second expansion-step, any possibly disturbing remainders
%% are already removed due to \romannumeral-expansion.
%%
%% No eTeX- or whatsoever extensions. No \if.. .Only \romannumeral,
%% digit 0, space token for terminating \romannumeral-expansion,
%% \string, \expandafter, \UD@firstoftwo, \UD@secondoftwo, {, }.
%%
%% May 20, 2016
%%
%% Ulrich Diez (e-mail: ud.usenetcorrespondence@web.de)
%%
\newcommand\UD@CheckWhetherNull[1]{%
\romannumeral0\expandafter\UD@secondoftwo\string{\expandafter
\UD@secondoftwo\expandafter{\expandafter{\string#1}\expandafter
\UD@secondoftwo\string}\expandafter\UD@firstoftwo\expandafter{\expandafter
\UD@secondoftwo\string}\expandafter\expandafter\UD@firstoftwo{ }{}%
\UD@secondoftwo}{\expandafter\expandafter\UD@firstoftwo{ }{}\UD@firstoftwo}%
}%
%%-------------------------------------------------------------------------
%% Keep only the K-th of L consecutive undelimited arguments.
%% ( IF K < 1 OR K > L just remove L consecutive undelimited arguments. )
%%.........................................................................
%% \UD@KeepKthOfLArguments{<integer number K>}%
%% {<integer number L>}%
%% {<Tokens to insert before K-th argument>}%
%% <L consecutive undelimited arguments>
%%
%% If K >= 1 and K <= L yields:
%% <Tokens to insert before K-th argument><K-th undelimited argument>
%% If K < 1 or K > L
%% (-> there is no K-th argument in the set
%% of <L consecutive undelimited arguments> )
%% yields:
%% <Tokens to insert before K-th argument>
%%
%% Examples:
%%
%% X\UD@KeepKthOfLArguments{3}{7}{<Tokens to insert>}{A}{B}{C}{D}{E}{F}{G}X
%% yields: X<Tokens to insert>CX
%%
%% X\UD@KeepKthOfLArguments{5}{2}{<Tokens to insert>}{A}{B}X
%% yields X<Tokens to insert>X
%%
%% X\UD@KeepKthOfLArguments{0}{2}{<Tokens to insert>}{A}{B}X
%% yields X<Tokens to insert>X
%%
%% X\romannumeral0%
%% \UD@KeepKthOfLArguments{3}{7}{ <Tokens to insert, be aware of the space behind the opening brace!>}{A}{B}{C}{D}{E}{F}{G}X
%% yields: X\romannumeral0 <Tokens to insert>CX
%% yields: X<Tokens to insert>CX
%% In case of embedding the whole thing in other expansion-contexts,
%% you need to have "hit" \romannumeral by only one \expandafter-chain for
%% obtaining the result...
%%
%% January 17, 2005
%%
%% Ulrich Diez (e-mail: ud.usenetcorrespondence@web.de)
%%
\newcommand\UD@KeepKthOfLArguments[2]{%
\expandafter\UD@KeepKthOfLArgumentsA
\expandafter{\romannumeral\number\number#1 000\expandafter}%
\expandafter{\romannumeral\number\number#2 000}%
}%
\newcommand\UD@KeepKthOfLArgumentsA[3]{%
\UD@CheckWhetherNull{#1}{%
\UD@RemoveNArguments{#2}{#3}{}%
}{%
\expandafter\UD@PassFirstToSecond
\expandafter{%
\UD@firstoftwo{}#1}{\UD@KeepKthOfLArgumentsB{#1}{#2}}{#2}{#3}%
}%
}%
\newcommand\UD@KeepKthOfLArgumentsB[5]{%
\UD@CheckWhetherNull{#1}{%
\UD@RemoveNArguments{#3}{\UD@RemoveNArguments{#2}{#5}}{}%
}{%
\UD@CheckWhetherNull{#2}{%
\UD@RemoveNArguments{#4}{#5}{}%
}{%
\expandafter\UD@PassFirstToSecond
\expandafter{%
\UD@firstoftwo{}#2}{\expandafter\UD@KeepKthOfLArgumentsB
\expandafter{%
\UD@firstoftwo{}#1}}{#3}{#4}{#5}%
}%
}%
}%
\newcommand\UD@RemoveNArguments[3]{%
\UD@CheckWhetherNull{#1}{#2#3}{%
\UD@firstoftwo{%
\expandafter\UD@RemoveNArguments
\expandafter{\UD@firstoftwo{}#1}{#2}{#3}%
}%
}%
}%
%%-------------------------------------------------------------------------
%% Check whether argument contains no exclamation-mark on top-brace-level:
%%.........................................................................
%% \UD@CheckWhetherNoExclamationMark{<Argument which is to be checked>}%
%% {<Tokens to be delivered in case that
%% argument which is to be checked does not contain !>}%
%% {<Tokens to be delivered in case that
%% argument which is to be checked does contain !>}%
\long\def\UD@RemoveToExclamationMark#1!{}%
\long\def\UD@CheckWhetherNoExclamationMark#1{%
\expandafter\UD@CheckWhetherNull\expandafter{\UD@RemoveToExclamationMark#1!}%
}%
%%-------------------------------------------------------------------------
%% Fork depending on some tokens:
%%.........................................................................
%% \ConditionalTextDesired{<Argument which is to be checked>}%
%% {<Tokens to be delivered in case <Argument which is to be checked> is "case 1" or "case 3" or "case 4">}%
%% {<Tokens to be delivered in case <Argument which is to be checked> is "case 2" or "case 5" >}%
%%
%% In case <Argument which is to be checked> is neither "case 1" nor
%% "case 2" the phrase "Error: Unknown parameter ``<Argument which is
%% to be checked>'' to \ConditionalTextDesired." will be delivered.
%%
\newcommand\@ConditionalTextDesired{}%
\long\def\@ConditionalTextDesired%
#1!!case 1!case 2!case 3!case 4!case 5!#2#3!!!!{#2}%
\newcommand\ConditionalTextDesired[1]{%
\romannumeral0%
\UD@KeepKthOfLArguments{%
\UD@CheckWhetherNoExclamationMark{#1}{%
\@ConditionalTextDesired
!#1!case 1!case 2!case 3!case 4!case 5!{1}%<- #1 is EMPTY
!!#1!case 2!case 3!case 4!case 5!{2}% <- #1 = case 1
!!case 1!#1!case 3!case 4!case 5!{3}% <- #1 = case 2
!!case 1!case 2!#1!case 4!case 5!{2}% <- #1 = case 3
!!case 1!case 2!case 3!#1!case 5!{2}% <- #1 = case 4
!!case 1!case 2!case 3!case 4!#1!{3}% <- #1 = case 5
!!case 1!case 2!case 3!case 4!case 5!{1}% <- #1 = something else without exclamation mark
!!!!%
}{1}% <- #1 = something else with exclamation mark
}{3}{ }% <- The remaining arguments of \UD@KeepKthOfLArguments.
% You could put the three text-arguments into the macro at this place.
% You can also provide only the one here, where the macro-parameter #1
% is needed and provide the other ones at run-time of the macro.
% The latter will be done for demonstration-purposes.
{%
Error: Unknown parameter ``#1'' to \texttt{\string\ConditionalTextDesired}.%
%In case eTeX-extensions are available you might wish to use \detokenize:
%Error: Unknown parameter ``\detokenize{#1}'' to \texttt{\string\ConditionalTextDesired}.%
}%
}%
\makeatother
\begin{document}
% This should yield "Error: Unknown parameter ``'' to \ConditionalTextDesired."
\ConditionalTextDesired{}
{some long text which is identical for case 1, case 3 and case 4.}%
{other text for case 2 and case 5.}%
% This should yield "Error: Unknown parameter ``!case 1'' to \ConditionalTextDesired."
\ConditionalTextDesired{!case 1}%
{some long text which is identical for case 1, case 3 and case 4.}%
{other text for case 2 and case 5.}%
% This should yield "Error: Unknown parameter ``case 6'' to \ConditionalTextDesired."
\ConditionalTextDesired{case 6}%
{some long text which is identical for case 1, case 3 and case 4.}%
{other text for case 2 and case 5.}%
% This should yield "some long text which is identical for case 1, case 3 and case 4."
\ConditionalTextDesired{case 1}%
{some long text which is identical for case 1, case 3 and case 4.}%
{other text for case 2 and case 5.}%
% This should yield "some long text which is identical for case 1, case 3 and case 4."
\ConditionalTextDesired{case 3}%
{some long text which is identical for case 1, case 3 and case 4.}%
{other text for case 2 and case 5.}%
% This should yield "some long text which is identical for case 1, case 3 and case 4."
\ConditionalTextDesired{case 4}%
{some long text which is identical for case 1, case 3 and case 4.}%
{other text for case 2 and case 5.}%
% This should yield "other text for case 2 and case 5."
\ConditionalTextDesired{case 2}%
{some long text which is identical for case 1, case 3 and case 4.}%
{other text for case 2 and case 5.}%
% This should yield "other text for case 2 and case 5."
\ConditionalTextDesired{case 5}%
{some long text which is identical for case 1, case 3 and case 4.}%
{other text for case 2 and case 5.}%
\end{document}
\def\CaseNumber{case 1} \ConditionalText{\CaseNumber}. If it is difficult to support both direct and macro use, I'd prefer macro use as shown here. – Peter Grill Apr 23 '17 at 10:57;-)– egreg Apr 23 '17 at 11:22*version can handle both cases so\IfStringCaseXis not needed. At least for this test case. – Peter Grill Apr 23 '17 at 11:45