0

My question is related but with some complication. How to replace last comma by dot after last encountered word?

% !TeX program = pdflatex                                   
% !TeX encoding = utf8


\documentclass[]{book}
\usepackage{filecontents}
\begin{filecontents*}{data.dat}
Number|Entry
1|Alpha
2|Beta
2|Gamma
3|Delta
\end{filecontents*}

\usepackage{datatool}
\DTLsetseparator{|}
\DTLloaddb{letters}{data.dat}

\begin{document}

\DTLforeach*[\Number=2]{letters}% database label
{\Number=Number, \Entry=Entry}% assignment
{% Stuff to do at each iteration:
            \DTLiflastrow{\Entry.}{\Entry,} % Here should be a right solution
}
\end{document}

enter image description here

2
  • A solution is not difficult in this particular case where at each iteration you just add \Entry. I'm afraid you can have more complicated settings, so I'm waiting for you to be more specific. Or are all applications like this and the one in your previous question? – egreg Apr 26 '19 at 14:00
  • @egreg All applications like in my MWE, maybe, one possible complication, the entries can be located not only in a row but also in a column. – sergiokapone Apr 26 '19 at 17:00
1

The other way round:

\documentclass[]{book}
\usepackage{filecontents}
\begin{filecontents*}{data.dat}
Number|Entry
1|Alpha
2|Beta
2|Gamma
3|Delta
\end{filecontents*}

\usepackage{datatool}
\DTLsetseparator{|}
\DTLloaddb{letters}{data.dat}

\begin{document}

\DTLforeach*[\Number=2]{letters}% database label
{\Number=Number, \Entry=Entry}% assignment
{\DTLiffirstrow{}{, }%
% Stuff to do at each iteration:
\Entry
}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.