/ Published in: VB.NET
The .NET Framework doesn't support automatic detection of character encoding in the default file I/O methods. This is a quick function that returns True in the specified file is Unicode.
Expand |
Embed | Plain Text
Private Function is_unicode(ByVal path As String) As Boolean Dim enc As System.Text.Encoding = Nothing Dim file As System.IO.FileStream = New System.IO.FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read) Dim bom As Byte() = New Byte(3) {} ' Get the byte-order mark, if there is one If (bom(0) = &HEF AndAlso bom(1) = &HBB AndAlso bom(2) = &HBF) OrElse (bom(0) = &HFF AndAlso bom(1) = &HFE) OrElse (bom(0) = &HFE AndAlso bom(1) = &HFF) OrElse (bom(0) = 0 AndAlso bom(1) = 0 AndAlso bom(2) = &HFE AndAlso bom(3) = &HFF) Then ' ucs-4 Return True Else Return False End If ' Now reposition the file cursor back to the start of the file Else Return False End If End Function
You need to login to post a comment.
