Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
Could you please add a minimal working example (MWE)? –  egreg Feb 14 '13 at 10:35
    
I just added a MWE. I'll like to get rid of the ". –  DaPhil Feb 14 '13 at 11:46
add comment

1 Answer

up vote 3 down vote accepted

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}
share|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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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