How to remove comments from vb.net source files?
-
as title. I searched it by google but no expected results. Anyone have solutions about this? Thanks in advance.
-
as title. I searched it by google but no expected results. Anyone have solutions about this? Thanks in advance.
Why would you want to do this? Are you looking for an automated means of removing the comments?
Dave Kreskowiak Microsoft MVP - Visual Basic
-
as title. I searched it by google but no expected results. Anyone have solutions about this? Thanks in advance.
Basically, Somethng like this..(I'm sure it can be Improved on..) but you'll get the idea...
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'Open and parse the source file.. TextBox1.Text = removeComments("c:\test.vb") ' 'Save your textbox to a file here.. ' End Sub ' Private Function removeComments(ByVal strFilePath As String) As String Dim sread As StreamReader = New StreamReader(strFilePath) Dim count As Integer = 0 While sread.Peek >= 0 Dim s As String = sread.ReadLine System.Math.Min(System.Threading.Interlocked.Increment(count), count - 1) End While sread.Close() Dim sr As StreamReader = New StreamReader(strFilePath) Dim fileData As String = "" Dim fi As FileInfo = New FileInfo(strFilePath) Dim i As Integer = 0 While i < count Dim str As String = sr.ReadLine If str.IndexOf("'") >= 0 Then fileData += removeSingleComment(str) Else fileData += str & vbCrLf End If System.Math.Min(System.Threading.Interlocked.Increment(i), i - 1) End While Return fileData End Function ' Private Function removeSingleComment(ByVal str As String) As String Dim length As Integer = str.Length - str.IndexOf("'") str = str.Replace(str.Substring(str.IndexOf("'"), length), "") Return str.Replace(" ", "") End Function
-
Why would you want to do this? Are you looking for an automated means of removing the comments?
Dave Kreskowiak Microsoft MVP - Visual Basic
yes
-
Basically, Somethng like this..(I'm sure it can be Improved on..) but you'll get the idea...
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'Open and parse the source file.. TextBox1.Text = removeComments("c:\test.vb") ' 'Save your textbox to a file here.. ' End Sub ' Private Function removeComments(ByVal strFilePath As String) As String Dim sread As StreamReader = New StreamReader(strFilePath) Dim count As Integer = 0 While sread.Peek >= 0 Dim s As String = sread.ReadLine System.Math.Min(System.Threading.Interlocked.Increment(count), count - 1) End While sread.Close() Dim sr As StreamReader = New StreamReader(strFilePath) Dim fileData As String = "" Dim fi As FileInfo = New FileInfo(strFilePath) Dim i As Integer = 0 While i < count Dim str As String = sr.ReadLine If str.IndexOf("'") >= 0 Then fileData += removeSingleComment(str) Else fileData += str & vbCrLf End If System.Math.Min(System.Threading.Interlocked.Increment(i), i - 1) End While Return fileData End Function ' Private Function removeSingleComment(ByVal str As String) As String Dim length As Integer = str.Length - str.IndexOf("'") str = str.Replace(str.Substring(str.IndexOf("'"), length), "") Return str.Replace(" ", "") End Function
thanks,i will try it
-
yes
The question still stands...Why would you want to do this?
Dave Kreskowiak Microsoft MVP - Visual Basic