In order to strip comments from code I would like to input from a file into TeX, I am using the following loop
\documentclass{article}
\def\getfirst#1#2\relax{#1}
\begin{document}
\openin1=mysrcfile.txt
\newcount\linecount
\global\linecount1
\loop
\unless\ifeof1
\read1 to \myinput
\if\expandafter\getfirst\expandafter\myinput\relax # % Here's the problem
\relax
\else
\myinput
\fi
\global\advance\linecount1
\repeat
\closein1
\end{document}
The code works without the loop, but inside the loop it gives me an error message, because #
indicates I would like to hand on parameters to the \loop
command, which is not what I want.
My first idea was of course escaping #
using \char"23
or \#
, but theses two expressions don't match the hash character and placing an \expandafter
in front of it doesn't seem to change that.
Does anyone of you know about a way which escapes the number sign, but still allows for matching it to input chars?
#
is a parameter token, or is it acceptable to read with an alternative catcode?