\@ifnextchar uses \futurelet that leaves the token in place. The token can be removed by using \let. \afterassignment helps to get the control, after the token is assigned and removed. Example:
\documentclass{article}
\usepackage{ltxcmds}
\makeatletter
\newcommand{\removeifnextchar}[3]{%
\begingroup
\ltx@LocToksA{\endgroup#2}%
\ltx@LocToksB{\endgroup#3}%
\ltx@ifnextchar{#1}{%
\def\next{\the\ltx@LocToksA}%
\afterassignment\next
\let\scratch= %
}{%
\the\ltx@LocToksB
}%
}
\makeatother
\newcommand*{\removeA}{%
\removeifnextchar{A}{[A is removed]}{[no A]}%
}
\begin{document}
\removeA ABC
\removeA abc
\end{document}

\ltx@ifnextchar or \@ifnextchar skips spaces. If you want to detect spaces, then use \ltx@ifnextchar@nospace.
Removing/reinserting
In general this is not possible, because \futurelet does not differentiate between implicit and explicit tokens. For example, the next token can be an opening curly brace { or it can be the command \bgroup or a command with the meaning of \bgroup.
This cannot be distinguished by \futurelet or \let. The curly brace can be removed by the \let trick above. However reinserting is much more difficult. The latter cases \bgroup or other command with the same meaning are much easier, they can be catched as macro and reinserted without need to modify the token.
The following example defines a macro \embrace that analyzes the following tokens and does different actions depending on the type of the token:
- Letters (catcode 11) are put in parentheses.
- Other characters (catcode 12) are put in square brackets.
- The space is replaced by the underscore.
- Any other token is removed.
- \par terminates the analysis.
The example file:
\documentclass{article}
\usepackage{ltxcmds}
\usepackage{xstring}
\makeatletter
\newcommand{\embrace}{%
\futurelet\embrace@token\@embrace
}
\newcommand{\embrace@test}[1]{%
\ifx\embrace@token#1%
\expandafter\ltx@firstoftwo
\else
\expandafter\ltx@secondoftwo
\fi
}
\newcommand*{\@embrace}{%
\embrace@test\@sptoken{%
\textunderscore
\afterassignment\embrace
\let\embrace@token= %
}{%
\expandafter\IfBeginWith\expandafter*%
\expandafter{\meaning\embrace@token}{the letter }{%
\embrace@letter
}{%
\expandafter\IfBeginWith\expandafter*%
\expandafter{\meaning\embrace@token}{the character }{%
\embrace@character
}{%
\ifx\embrace@token\par
\else
\@latex@warning{embrace: Token [\meaning\embrace@token] removed}%
\afterassignment\embrace
\fi
\let\embrace@token= %
}%
}%
}%
}
\newcommand*{\embrace@letter}[1]{%
(#1)%
\embrace
}
\newcommand*{\embrace@character}[1]{%
[#1]%
\embrace
}
\begin{document}
\embrace ABC 123\par
\embrace a 1{!}#&$x%
\end{document}

And the removed tokens:
LaTeX Warning: embrace: Token [begin-group character {] removed on input line 54.
LaTeX Warning: embrace: Token [end-group character }] removed on input line 54.
LaTeX Warning: embrace: Token [macro parameter character #] removed on input line 54.
LaTeX Warning: embrace: Token [alignment tab character &] removed on input line 54.
LaTeX Warning: embrace: Token [math shift character $] removed on input line 54.
expl3there is\peek_charcode_remove:NTF– egreg Sep 17 '12 at 11:34