c# - How can I delete all the comments in my code? -


i'm new c#, , want develope program delete comments after // in code. there simple code recommended purpose?

first point, seems bad idea. comments useful.

taking exercise,

edit: simple solution fail on case @bubbafat mentions (and propbably more). still work ok on source files.

  1. read text 1 line @ time.
  2. find last occurrence of //, if using string.lastindexof()
  3. remove text after (including) '//' when found
  4. write line output

    • ad 1: can open textreader using system.io.file.opentext(), or file.readlines() if can use fx4
    • also open output file using system.io.file.writetext()
    • ad 3: int pos = line.lastindexof("//"); if (pos >= 0) { line = line.substring(0, pos); }

Comments

Popular posts from this blog

Javascript line number mapping -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -