·上一篇:VB ListBox 添加不重復的值
·下一篇:VB 二進制數組轉換成16進制字符串函數
VB 判斷是否文本文件
- VBScript code復制代碼
Option Explicit '************************************************************************* '**作 者:新興網絡 '**原 文:http://www.71216532.buzz/Tech/Program/VisualBasic/666.html '**如果需要轉載,請保留作者信息謝謝 '************************************************************************* Public Function IsTextFile(Bytes() As Byte) As Boolean Dim i As Long, AscN As Long, Length As Long Length = UBound(Bytes) + 1 If Length < 3 Then IsTextFile = IsGB(Bytes, Length) Exit Function ElseIf Bytes(0) = &HEF And Bytes(1) = &HBB And Bytes(2) = &HBF Then IsTextFile = True Exit Function End If Do While i <= Length - 1 If Bytes(i) < 128 Then i = i + 1 AscN = AscN + 1 ElseIf (Bytes(i) And &HE0) = &HC0 And (Bytes(i + 1) And &HC0) = &H80 Then i = i + 2 ElseIf i + 2 < Length Then If (Bytes(i) And &HF0) = &HE0 And (Bytes(i + 1) And &HC0) = &H80 And (Bytes(i + 2) And &HC0) = &H80 Then i = i + 3 Else IsTextFile = IsGB(Bytes, Length) Exit Function End If Else IsTextFile = IsGB(Bytes, Length) Exit Function End If Loop If AscN = Length Then IsTextFile = IsGB(Bytes, Length) Else IsTextFile = True End If End Function Private Function IsGB(Bytes() As Byte, FileSize As Long) As Boolean Dim ObjStream As Object, ret As String Set ObjStream = CreateObject("ADODB.Stream") With ObjStream .Type = 1 .Mode = 3 .open .Write Bytes .Position = 0 .Type = 2 .Charset = "GB2312" ret = .ReadText .Close End With If LenB(StrConv(ret, vbFromUnicode)) = FileSize Then IsGB = True Else IsGB = False End If End Function
評論內容只代表網友觀點,與本站立場無關!
評論摘要(共 0 條,得分 0 分,平均 0 分)
查看完整評論