[Source] Remove comments 05-28-2013, 02:57 AM
#1
Here's a sub you can use to clean a source code from comments. It displays how long it took for the script to run and how many comments were removed.
Usage
Code:
'
Sub RemoveComments(ByVal Input As String, ByVal CommentPrefix As String)
Dim Time As Date = Now
Dim Comments As Integer = 0
Dim Clean As String = ""
Dim Code As String() = Input.Split(Environment.NewLine)
For Each Line As String In Code
If Line.Contains(CommentPrefix) Then
Clean &= Line.Split(CommentPrefix)(0)
Comments += 1
Else
If Line <> "" Then
Clean &= Line
End If
End If
Next
My.Computer.Clipboard.SetText(Clean)
MessageBox.Show("Completed after " & DateDiff(DateInterval.Second, Time, Now) & " seconds!" _
& Environment.NewLine & _
"Removed " & Comments & " comments from the code!" _
& Environment.NewLine & _
"Output saved to clipboard!")
End Sub
Usage
Code:
'
RemoveComments(TextBox1.Text, "//")