Comments in Text file

Ford-p

Active member
Joined
Mar 1, 2007
Messages
30
Programming Experience
Beginner
Hey,

I have some code that opens a text file using "System.IO.StreamReader" and reads the next line with "ReadLine()". It then does some functions and loops to the next line.

What I'm trying to do is add comments to my text file that VB will ignore. I would like to have # or ' as the character before my comment.

My text file looks like this:
VB.NET:
# comment 1
line 1
line 2
line 3 # comment 2
Can anyone point me in the right direction?

Thanks,
Joe

P.S. Is it me or has this site had lots of downtime?
 
It's you

Try:
VB.NET:
Imports System.Text.RegularExpressions
 
...
  'this MUST go outside the loop that reads the file
  Dim commentPattern As New Regex("[#].*", RegexOptions.Compiled)
 
 
  ...
 
  'after you read the line, strip the comments out
  line = commentPattern.Replace(line, "")
 
Back
Top