File Exchange Pick of the Week

Our best user submissions

Want to get rid of your code comments?

Brett's Pick this week allows you to strip comments from your code, should you need to do so.

Several years ago--while building several large, multi-file applications--I found myself getting unwanted output scrolling to my command window. Clearly, I had omitted some line-terminating semicolons somewhere in my morass of code. Finding these instances was tedious and time-consuming (and a task that MLINT now makes trivially easy).

I decided to write a function to detect missing semicolons, but quickly found that coding to ignore comments was beyond my capacity--at least at the time.

Fortunately, Peter Acklam (whom you may know as a frequent contributor to the fine CSSM newsgroup, and as a MATLAB vectorization guru), came to my rescue and, in response to my queries, posted his Comment-Stripping Toolbox.

I haven't had to use my missingsemicolons function in quite a while, but every now and then I still have occasion to strip comments from some MATLAB code. And when I do, I still turn to Peter's submission.

The Comment-Stripping Toolbox allows you to strip comments from a string, or from a file specified by name or by file I.D. One of the things that impressed me the most about Peter's submission was that it reflected his mastery of regular expressions:

If you ever need to strip comments, or just want to see some impressive code, try out Peter's file, and let us know about it here.

Published with MATLAB® 7.8

  • print
  • send email


To leave a comment, please click here to sign in to your MathWorks Account or create a new one.