我的问题是有关的但有些复杂。如何用最后一个逗号替换最后一个逗号遭遇单词?
% !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}
答案1
反过来:
\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}