In the following MWE, the command \testStringNotEmpty tests if the argument is empty. This test is robust in the sense that the argument can contain a command or an environment... The environment monenv willy display "Empty" if the body (which i capture in \BODY) is empty, and "not empty" in the other case. My problem is that if the body of monenv is the command \macom which expands to "empty", then it has a different behaviour than the one i expected. This is probably because one should sort of completely expand \BODY before to call \testStringNotEmpty, and my attempt with the \expandafter does not seem to work...
\documentclass{article} \usepackage{environ} \makeatletter \newcommand{\testStringNotEmpty}[1]{% \ifnum\pdfstrcmp{\unexpanded{#1}}{}=\z@ \expandafter\@secondoftwo \else \expandafter\@firstoftwo \fi } \makeatother \NewEnviron{monenv}% {% \expandafter\testStringNotEmpty\expandafter{\BODY}% {Environment = NOT empty}% {Environment = Empty}% } \newcommand{\macom}{} \begin{document} \begin{monenv} \end{monenv} \begin{monenv} \macom \end{monenv} \begin{monenv} \macom \macom \end{monenv} \end{document} EDIT : Using the solution of egreg to expand \BODY in the environment monenv, i encounter now some problems if the content of monenv is more complicated (and reflect now my actual code).
So, i redefine monenv according to egreg's solution. I define the following command :
\newcommand{\hint}[1]{% \testStringNotEmpty{#1}{hint : #1}{}} and i test it with :
\begin{monenv} \hint{} \end{monenv} \begin{monenv} \hint{} \hint{} \end{monenv} which gives me "empty" for the first one (as expected) and "NOT empty" for the second one, which i don't want...
\hint{}: this makes the contents non empty.\DTLsubstituteall...