In the question Use xifthen: how set \cnttest not equal number, I learnt how to perform if-then-else tests where the condition compares two integers. Now, I would like to do the same, but with string comparisons instead of integer comparisons. For example, I would like to test values stored in a macro \No
where the values could be X
, Y
, Z
, etc.
My minimal code:
\RequirePackage{filecontents}
\begin{filecontents*}{test.csv}
Acol, Bcol, NoCol
A0,0000,0
Ax,Bx,1
Ay,By,2
A1,B22,3
A2,B44,4
A3,29,5
A3,29,99
A3,449,100
AX,500,X
AY,500,Y
AZ,600,Z
\end{filecontents*}
\documentclass{article}
\usepackage[a5paper,landscape]{geometry}
\usepackage{ifthen}
\usepackage{datatool}
\DTLloaddb{mydata}{test.csv}
\newcommand{\inserpageX}{%
\subsubsection*{Page X}
\newpage
}
\newcommand{\inserpageY}{%
\subsubsection*{Page Y}
\newpage
}
\newcommand{\inserpageZ}{%
\subsubsection*{Page Z}
\newpage
}
\begin{document}
\DTLforeach*{mydata}{\A=Acol, \B=Bcol, \No=NoCol}%
{%
\ifthenelse{\No=0}% X
{\newpage
\inserpageX}%
{
\ifthenelse{\No=1}% Y
{\newpage \inserpageY}%
{
\ifthenelse{\No=100}% Z
{\newpage \inserpageZ}%
{
{\No \hspace{1cm}\B \hspace{5cm}\A\par}
}
}
}
}
\end{document}
How can I distinguish between the three cases \No
= X, \No
= Y and \No
= Z that occur in the sample test.csv
file?
Thanks in advance.
NoCol
column of the provided data file contains only numbers, notX
,Y
, etc. 2) You mentionxifthen
but are actually usingifthen
(these are two different packages!).ifthen
has a string equality test that is\equal{string1}{string2}
, but it would probably be wise to explain clearly what you want to do in the end, instead of what you think you need to do in order to achieve your goal.