# Hiding code comments in listings

I'm using listings package and \lstinputstring command to insert code from a file. Is it possible to hide code comments in inserted code? I'm using a language in which # starts a comment and it lasts until the end of line. I tried to do this with escapeinside option, but I think I don't understand how it works.

-
From your comment below you say that you want lines with only comments to be ignored. In this case I'd recommend just pre-processing the file. – Will Robertson Nov 19 '10 at 4:02
– Jubobs Mar 5 '14 at 11:09

I'd just cheat, and specify commentstyle=\color{white}. This is even used in the manual :-) It does have the defect that if you print on non-white paper you'll see it, but that's usually not happening. Of course, if you have a non-white background, just use the background color instead.
Edit: For block comments, you can also use morecomment=[is]{/*}{*/}, where the i makes the comment completely invisible; however, this doesn't work for single-line comments, instead deleting all of the source code after the first single-line comment it finds.
Having poked around in the manual: if you specify morecomment=[is]{/*}{*/}, the i makes the comment completely invisible, but I can't get this to work right with line comments (it just deletes the whole rest of the text after the first comment, not even reserving space for it). – Antal Spector-Zabusky Nov 19 '10 at 10:58
I got away with morecomment=[is]{\#\%}{\#:}, this required only minor changes to source files and looks well. Thanks for the i tip. – Marek Sapota Nov 19 '10 at 15:21