部分文字列の比較

部分文字列の比較

次のコードを実行したいのですが、2番目のテストは失敗します。

! Argument of \@secondoftwo has an extra }.

何が欠けているのでしょうか?

\documentclass{article}
\usepackage{xstring,ifthen}
\newcommand{\mytest}[1]{%
   \newcommand{\s}{\StrChar{#1}{3}}
   \newcommand{\x}{c}
   3rd charactor of input is: \s ~equal to \x \\
   1st test: \IfStrEq{\x}{c}{true}{false} \\
   2nd test: \IfStrEq{\s}{c}{true}{false}
}
\begin{document}
   \mytest{abcd}
\end{document}

助けていただければ幸いです。ありがとう、マルテ

答え1

3番目のキャラクターとして定義するので\sはなく、複雑な指示のセットとして定義します印刷3番目の文字。

より優れた機能を使用するxstring:

\documentclass{article}
\usepackage{xstring}
\newcommand{\mytest}[1]{%
   \StrChar{#1}{3}[\maltetest]%
   Third charactor of input is: \maltetest\ equals c\\
   Test: \IfStrEq{\maltetest}{c}{true}{false}%
}
\begin{document}
   \mytest{abcd}
\end{document}

ここに画像の説明を入力してください

この方法では、\maltetest入力文字列の 3 番目の文字が正確に含まれることになります。

関連情報