vb编写去除C程序的注释
发布网友
发布时间:2024-09-28 10:22
我来回答
共3个回答
热心网友
时间:2024-09-29 20:03
'不简单,刚刚调试好
'添加窗体Form1,按钮Command1,要处理的文件默认为"C:\1.cpp"
'代码如下:
Private Sub Command1_Click()
Command1.Enabled = False
Dim strResult As String
strResult = delStep1("C:\1.cpp") '第一步,去除“//”
MsgBox strResult
strResult = delStep2(strResult) '第二步,去除“/**/”
Command1.Enabled = True
MsgBox strResult
End Sub
'得到不含"//"的字符串
Private Function delStep1(fName As String) As String
Dim tempInput, getString As String
Open fName For Input As #1
Do While Not EOF(1)
Line Input #1, tempInput
If InStr(tempInput, "//") > 0 Then
tempInput = Mid(tempInput, 1, InStr(tempInput, "//") - 1) '这里先去除"//"
End If
If tempInput <> "" Then
getString = getString & tempInput & vbCrLf
End If
Loop
getString = Left(getString, Len(getString) - 2) '去除末尾回车换行
delStep1 = getString
Close #1
End Function
'得到不含"/**/"的字符串
Private Function delStep2(strCode As String) As String
Dim strResult As String
Dim l As Long
Dim isCanCopy As Boolean
isCanCopy = True
For l = 1 To Len(strCode)
If Mid(strCode, l, 2) = "/*" Then
isCanCopy = False
ElseIf Mid(strCode, l, 2) = "*/" Then
l = l + 2
isCanCopy = True
End If
If isCanCopy Then strResult = strResult & Mid(strCode, l, 1)
Next
delStep2 = strResult
End Function
热心网友
时间:2024-09-29 20:04
逐行读入,分析“//”和“/* */”
热心网友
时间:2024-09-29 20:04
用循环语句 逐行读入,
如 do---loop, while 等等
用字符串分别查找"//","/*"和"*/"符号,然后分别做以不同的处理.
1), 在"//"同行内,给其后果的内容去掉.
2),在"/*"和"*/"符号之间同行和不同行之间的内容去掉.