Minimal not working example:
\documentclass{article}
\usepackage{amsmath,amsthm,amssymb,varwidth,xstring,environ}
\newsavebox{\tempbox} %Allows to use fbox in newenvironment
\makeatletter
\NewEnviron{result}[1][\textwidth]{%
\StrPosition{\BODY}{\qedhere}[\@Position]%
\IfEq{\@Position}{0}{%
\BODY
}{%
%% Does contain \qedhere
}%
}%
\makeatother
\begin{document}
\begin{result}[7cm]
abc $\mathcal{A}$
\end{result}
\end{document}
The code above doesn't work for an unknown reason. Enven stranger is that if I use my original code :
\documentclass{article}
\usepackage{amsmath,amsthm,amssymb,varwidth,xstring,environ}
\newsavebox{\tempbox} %Allows to use fbox in newenvironment
\makeatletter
\NewEnviron{result}[1][\textwidth]{%
\StrPosition{\BODY}{\qedhere}[\@Position]%
\IfEq{\@Position}{0}{%
%% Does not contain \qedhere
\begin{center} %The box will be centered
\begin{lrbox}{\tempbox} %Allows to use fbox in newenvironment
\begin{varwidth}{#1} %Minipage that set its width to the text width it contains
\begin{center}
\BODY
\end{center}
\end{varwidth}
\end{lrbox}\fbox{\usebox{\tempbox}}
\end{center}
}{%
}%
}%
\makeatother
\begin{document}
% \begin{result}[7cm]
% abc $\mathcal{A}$
% \end{result}
\end{document}
and if I test with the following code, it works :
\begin{result}[7cm]
abc $\mapsto $
\end{result}
\begin{center}
\begin{lrbox}{\tempbox}
\begin{varwidth}{7cm}
\begin{center}
abc $\mathcal{A}$
\end{center}
\end{varwidth}
\end{lrbox}\fbox{\usebox{\tempbox}}
\end{center}