I'd like to have access to the number associated to a box by giving its control sequence. This control sequence is defined by \newbox using \chardef so a "control sequence box" expands to something like \char"1A. I'd like to get that hexadecimal 1A. Here is what I did so far.
\documentclass{article}
\begin{document}
\newbox\mybox
\edef\temp{%
\def\noexpand\stripchar\detokenize{\char"}##1\noexpand\endstripchar{##1}}
\temp
\def\printboxnumber#1{%
\expandafter\stripchar\meaning#1\endstripchar}
\printboxnumber\mybox
\end{document}
The \detokenize is there to take care of \catcode change due to the use of \meaning in \printboxnumber. Unfortunately, I get
! Use of \stripchar doesn't match its definition.
<inserted text> \char"
1A
l.13 \printboxnumber\mybox
What's wrong?
\number\mybox... Good exercise anyway :-) Thanks for pointing out the\detokenizesubtlety. – cjorssen Oct 27 '11 at 13:37\chardefor\mathchardeftoken can be used when TeX is looking for a\@one, that is often used in packages, is defined as\chardef\@ne=1.