datatool:删除特定字符

datatool:删除特定字符

如何在使用 datatool 从文件加载表格时删除字符?就我而言,我喜欢删除数据中出现的每个双引号。

\documentclass{minimal}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{datatool}
\usepackage{multido}
\usepackage{filecontents}

\begin{filecontents*}{members.csv}
"Rolle/Status","Vorname","Nachname"
"Mitglied","FirstName1","LastName1"
"Mitglied","FirstName2","LastName2"
"Mitglied","FirstName3","LastName3"
\end{filecontents*}

\DTLsetdelimiter{,}
\DTLloaddb{members}{members.csv}

\begin{document}

\multido{\nx = 1+1}{\DTLrowcount{members}}{
  \DTLgetvalue{\studentlastname}{members}{\nx}{3}
  \DTLgetvalue{\studentfirstname}{members}{\nx}{2}
  \studentlastname
  \studentfirstname
}

\end{document}

顺便问一下,当我在 \DTLgetvalue 和 \studentlastname 之间添加一行时,会出现多个错误。这是什么原因?

答案1

没有必要使用\multido来循环遍历数据库的行,因为datatool提供了\DTLforeach;请参阅 手册中的第 5.4 节datatool

如果你确定全部条目位于引号之间,这应该有效:

\documentclass{article}
\usepackage{datatool}
\usepackage{filecontents}

\begin{filecontents*}{members.csv}
"Rolle/Status","Vorname","Nachname"
"Mitglied","FirstName1","LastName1"
"Mitglied","FirstName2","LastName2"
"Mitglied","FirstName3","LastName3"
\end{filecontents*}

\newcommand\stripquotes[1]{\expandafter\dostripquotes#1}
\def\dostripquotes"#1"{#1} % \def is necessary here

\DTLsetdelimiter{,}
\DTLloaddb{members}{members.csv}

\begin{document}

\DTLforeach{members}{%
  \studentfirstname="Vorname",
  \studentlastname="Nachname"}
  {\stripquotes{\studentlastname}, \stripquotes{\studentfirstname}\par}

\end{document}

相关内容