% This file is embedded in datatool-user.pdf version 3.4.1 2025-04-25
% Example 53 Elements of a CSV List
% Label: "ex:listelements"
% arara: pdflatex
% arara: pdfcrop
\documentclass[12pt]{article}
\pagestyle{empty}
\usepackage{datatool-base}
\newcommand{\mylist}{ant,{bee, wasp and hornet},fly} 
\begin{document}
List: \DTLformatlist{\mylist}. 

Number of elements: \DTLnumitemsinlist{\mylist}{\total}\total. 

Second element: \DTLlistelement{\mylist}{2}. 

Fetch third element:
\DTLfetchlistelement{\mylist}{3}{\myelem}\myelem. 

\LaTeX3 List:
\ExplSyntaxOn
\clist_set:NV \l_tmpa_clist \mylist
\clist_use:Nnnn \l_tmpa_clist { ~ and ~ } { , ~ } { , ~ and ~ }
\ExplSyntaxOff 

Number of elements:
\ExplSyntaxOn
\clist_count:N \l_tmpa_clist .
\ExplSyntaxOff 

Second element:
\ExplSyntaxOn
\clist_item:Nn \l_tmpa_clist { 2 } .
\ExplSyntaxOff 

Fetch third element:
\ExplSyntaxOn
\tl_set:Ne \l_tmpa_tl { \clist_item:Nn \l_tmpa_clist { 3 } }
\l_tmpa_tl .
\ExplSyntaxOff 
\end{document}
