工作需要,针对java文件,作了一个行数统计的工具。统计的主要代码如下:
Set srcIn = fso.OpenTextFile(fileNm, ForReading)
Do While Not srcIn.AtEndOfStream
buf = srcIn.ReadLine
'java总行数
allLinex = allLinex + 1
'java空白行
If Not flg And Trim(Replace(buf, vbTab, "")) = "" Then
'Debug.Print fileNm & ":" & allLinex
blankLinex = blankLinex + 1
End If
'java注释行
If flg Then
If InStr(buf, "*/") > 0 Then
flg = False
End If
commentLinex = commentLinex + 1
ElseIf InStr(Trim(Replace(buf, vbTab, "")), "//") = 1 Then
commentLinex = commentLinex + 1
End If
If InStr(Trim(Replace(buf, vbTab, "")), "/*") = 1 Then
flg = True
commentLinex = commentLinex + 1
End If
If flg And InStr(buf, "*/") > 0 Then
If Mid(Trim(Replace(buf, vbTab, "")), Len(Trim(Replace(buf, vbTab, ""))) - 1) = "*/" Then
flg = False
End If
End If
Loop
'java实行行数
execLinex = allLinex - blankLinex - commentLinex
广告:
优衣库官方旗舰店提示:冬日寒冷,请注意保暖,