Suppress ampersand in external text

You can set locally the catcode of & when reading the data. It will not disturb the use of & later, and unlike \detokenize it will not break other commands like non-ascii input in your input:

    \documentclass[10pt]{article}
    \usepackage[T1]{fontenc}
    \usepackage[utf8]{inputenc}
    \usepackage[a4paper]{geometry}

    \catcode`\&=12
    \newcommand{\txtstring}{Father & Sons & Mütter}
    \newcommand{\txtstringtwo}{Father \& Sons & Mütter}
    \newcommand{\txtstringthree}{\detokenize{Father & Sons & Mütter}}
    \catcode`\&=4

    \begin{document}

    \txtstring: OK
    \par
    \txtstringtwo: OK
    \par
    \txtstringthree: Bad

    \begin{tabular}{ll}
    blub & bla
    \end{tabular}
    \end{document}

enter image description here


Here's a solution that just uses \DTLloadrawdb instead of \DTLloaddb:

\documentclass{article}

\usepackage{filecontents}
\usepackage{datatool}

\begin{filecontents*}{test.csv}
CVR,CompanyName,LastName,FirstName,Address,PostCode,City
12 23 45 56,Fox & Sons,Fox,Red,Fowl Street 1,4567,Fox Town
45 56 67 78,Elephant & Daughters,Fant,Eli,Africa Road 1,1259,Mega City
\end{filecontents*}

\DTLloadrawdb{testdata}{test.csv}
\begin{document}
\DTLforeach{testdata}%
{%
    \CV=CVR,%
    \CN=CompanyName,%
    \LN=LastName,%
    \FN=FirstName,%
    \AD=Address,%
    \PC=PostCode,%
    \CT=City%
}%
{%
  \CV, \CN, \LN, \FN, \AD, \PC, \CT\par
}
\end{document}

The ampersands are automatically converted to \& when the data is read from the CSV file. Nothing special needs to be done in the \DTLforeach loop. The above example produces:

image of document

Similarly for eight of the other special characters. The only special character not to be mapped is the backslash. You can also add your own mappings (before \DTLloadrawdb). For example:

\DTLrawmap{£}{\pounds}