I'm trying to master the art of parsing text one character at a time. The following is what I've discovered so far. Is this as good as it gets? I would really prefer not to do all those \edefs as they waste RAM.
\documentclass{article}
\tracingmacros=1
\newcommand{\scanA}[1]% #1 = text to scan
{\futurelet\token\scanB#1 % does nothing for me
\scanC#1 % splits off first token
\edef\next{#1\relax}%
\expandafter\scanD\next% refined version
\expandafter\scanD\next% okay, scaning underway
\expandafter\scanD\next
\expandafter\scanE\next{} % end
}
\def\scanB #1 {\noindent scanB:\par token \token \par\#1 #1 \par}
\def\scanC #1#2 {\noindent scanC:\par\#1 #1 \par\#2 #2 \par}
\def\scanD #1#2\relax{\noindent scanD:\par\#1 #1 \par\#2 #2 \par
\edef\next{#2\relax}}
\def\scanE #1#2\relax{\noindent scanE:\par\#1 #1 \par\#2 \meaning #2
\ifx#2\relax \relax\par The end.\par\fi}
\begin{document}
\scanA{test}
\end{document}

Lessons Learned: (Okay, I should have known some of this already, but didn't.)
\documentclass{article}
\tracingmacros=1
\def\scanA#1{(#1)}% copies 1 token
\def\scanB#1 {(#1)}% copies 1 word
\newcommand{\scan}[1]{\scanC#1\END}% loop until \END
\def\scanC#1{\ifx#1\END\else(#1)\expandafter\scanC\fi}% expand \fi before \scanC
\newcommand{\scanwords}[1]{\let\between=\empty\scanD#1 \END}
\def\scanD#1 {\ifx#1\END\else\between
\let\between=\wordfill% insert \wordfill between words
\scanC#1\END% scan letters of word
\expandafter\scanD\fi% expand \fi before \scanD
}
\def\END{almost anything}
\def\wordfill{( )}% \def once, \let repeatedly
\begin{document}
\Huge
\scanA two words
\scanB two words
\scan{t e s t}% ignores spaces
\scanwords{two words}
\end{document}

All of the answers are better than my first attempt, but I need to accept one to "close" the question. Since my goal was to LEARN how to scan better...
Here is another variant I've been playing with. It stores the text as a token list.
\documentclass{article}
\usepackage{lipsum}
\def\END{\END}
\newtoks\mytoks
\def\parse{\futurelet\next\special}% some tokens are ignored
\def\special{% \space and \bgroup
\expandafter\ifx\space\next\relax \mytoks=\expandafter{\the\mytoks\space}\fi%
\ifx\bgroup\next\relax \expandafter\copygroup\else
\expandafter\normal\fi}
\def\copygroup#1{\mytoks=\expandafter{\the\mytoks{#1}}\parse}%
\def\normal#1{%
\ifx\END#1\relax
\the\mytoks% end of environment
\else
\mytoks=\expandafter{\the\mytoks#1}%
\expandafter\parse\fi}
\begin{document}
\parse
\begin{center}
enviroment test
\end{center}
\noindent\hbox{parse} test
\END
\end{document}





expl3if you haven't already. That said, I'm not sure exactly what you're trying to do – what is as good as it gets? I'm not sure what you're referring to. – Sean Allred Mar 14 '15 at 18:18