我正在尝试对VBA中的某些SAS代码进行一些文本分析。我想跳过评论。
但我只能找到一种使用C
语句一次读取一行的方法。但这使得很难避免注释与未注释的代码相同,如
Line Input
所以我想知道是否可以在VBa中一次读取一个字符,直到遇到评论开始?
答案 0 :(得分:2)
由于文件很小,一个选项是将整个文件读入一个字节数组:
Dim handle As Long
Dim bytes() As Byte
Dim path As String
path = "C:\somefile.txt"
handle = FreeFile
Open path For Binary Access Read As handle
ReDim bytes(LOF(handle) - 1&)
Get handle, , bytes
Close handle
Dim char As Variant
For Each char In bytes
Debug.Print Chr$(char)
Next char