📄 stringinfile.txt
字号:
'****************************************************************
' Name: Does a file contain a string?
' Description: Determines whether a file contains a string
' By:Daniel Wiman
'
' Inputs:None
' Returns:None
' Assumes:None
' Side Effects:None
' Requires: Nothing
'
'Code provided by Robert's Visual Basic Homepage 'as is', without
' warranties as to performance, fitness, merchantability,
' and any other warranty (whether expressed or implied).
'****************************************************************
Function FileContains (FileName As String, SearchText As String) As Long
Dim FileNumber As Integer
Dim FileLength As Long
Dim Chunk As String
Dim ChunkStart As Long
Dim FoundAt as LongConst MaxChunk = 20000
On Error GoTo FileContainsError
FileNumber = FreeFile
Open FileName For Binary Access Read Shared As FileNumber
FileLength = LOF(FileNumber)
ChunkStart = 0
Do Until ChunkStart = FileLength
If FileLength - ChunkStart > MaxChunk Then
Chunk = Input$(MaxChunk, FileNumber)
ChunkStart = ChunkStart + MaxChunk - Len(SearchText)
Else
Chunk = Input$(FileLength - ChunkStart, FileNumber)
ChunkStart = FileLength
End If
FoundAt = InStr(Chunk, SearchText)
If FoundAt > 0 Then
FileContains = FoundAt
Exit Do
End If
Loop
Close FileNumber
Exit Function
FileContainsError:
Select Case Err
Case Else
MsgBox Error$ & " on file " & FileName
End Select
Exit Function
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -