Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. How to remove comments from vb.net source files?

How to remove comments from vb.net source files?

Scheduled Pinned Locked Moved Visual Basic
csharptutorialquestion
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JackChen626
    wrote on last edited by
    #1

    as title. I searched it by google but no expected results. Anyone have solutions about this? Thanks in advance.

    D P 2 Replies Last reply
    0
    • J JackChen626

      as title. I searched it by google but no expected results. Anyone have solutions about this? Thanks in advance.

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Why would you want to do this? Are you looking for an automated means of removing the comments?

      Dave Kreskowiak Microsoft MVP - Visual Basic

      J 1 Reply Last reply
      0
      • J JackChen626

        as title. I searched it by google but no expected results. Anyone have solutions about this? Thanks in advance.

        P Offline
        P Offline
        progload
        wrote on last edited by
        #3

        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
        
        J 1 Reply Last reply
        0
        • D Dave Kreskowiak

          Why would you want to do this? Are you looking for an automated means of removing the comments?

          Dave Kreskowiak Microsoft MVP - Visual Basic

          J Offline
          J Offline
          JackChen626
          wrote on last edited by
          #4

          yes

          D 1 Reply Last reply
          0
          • P progload

            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
            
            J Offline
            J Offline
            JackChen626
            wrote on last edited by
            #5

            thanks,i will try it

            1 Reply Last reply
            0
            • J JackChen626

              yes

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              The question still stands...Why would you want to do this?

              Dave Kreskowiak Microsoft MVP - Visual Basic

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups