- Function remove_utf8_BOM(ByVal file)
- Dim oStream, s, i
- Set oStream = CreateObject("ADODB.Stream")
- oStream.Type = 1 'adTypeBinary
- oStream.Mode = 3 'adModeReadWrite
- oStream.Open()
- With CreateObject("ADODB.Stream")
- .Type = 1 'adTypeBinary
- .Mode = 3 'adModeReadWrite
- .Open()
- On Error Resume Next
- Err.Clear()
- .LoadFromFile file
- If Err.Number <> 0 Then remove_utf8_BOM = Err.Description : Exit Function
- If .Size < 3 Then remove_utf8_BOM = "False" : Exit Function 'no utf-8 BOM
- s = ""
- For i = 0 To 2
- s = s & Hex(AscB(.Read(1)))
- Next
- If s <> "EFBBBF" Then remove_utf8_BOM = "False" : Exit Function 'no utf-8 BOM
- .Position = 3
- .CopyTo oStream
- .Close()
- End With
- Err.Clear()
- oStream.SaveToFile file, 2 'adSaveCreateOverWrite
- If Err.Number <> 0 Then remove_utf8_BOM = Err.Description : Exit Function
- oStream.Close()
- remove_utf8_BOM = "True" 'write file complete
- End Function
复制代码 这个用于去除utf-8文件的BOM |