3

How can I get rid of a character while loading a table from a file with datatool? In my case, I like to get rid of every double quote that appears within the data.

\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}

By the way, when I add an extra line between \DTLgetvalue and \studentlastname, I'll get multiple errors. What is the reason?

3

There's no need to use \multido for cycling through the rows of a database, since datatool provides \DTLforeach; see section 5.4 in the manual of datatool.

If you're sure that all entries are between quotes, this should work:

\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}
|improve this answer|||||
  • Problem: I need the multido loop since I want to do something else for each row. To be precise: I want to make an exam where on each the student name and an ID is written. I am running through a multido loop to print an exam for every row=every student. – DaPhil Feb 14 '13 at 12:07
  • @DaPhil There's no need of \multido. – egreg Feb 14 '13 at 12:20

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.