Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function GetUnicodeEncoding(lcFilename As String)
- Local lcRet, lnHandle
- * -- Encoding Representation (hexadecimal) Representation (dec)
- * -- UTF-8[t 1] EF BB BF 239 187 191
- * -- UTF-16 (BE) FE FF 254 255
- * -- UTF-16 (LE) FF FE 255 254
- lcRet = "FILEOPENERROR"
- lnHandle = Fopen(lcFilename)
- If lnHandle > 0
- =Fseek(lnHandle, 0, 0)
- lcBytes = Fread(lnHandle, 3)
- Fclose(lnHandle)
- Do Case
- Case Asc(Left(lcBytes, 1)) = 239 ;
- and Asc(substr(lcBytes, 2, 1)) = 187 ;
- and Asc(right(lcBytes, 1)) = 191 ;
- lcRet = "UTF-8"
- Case Asc(Left(lcBytes, 1)) = 254 ;
- and Asc(substr(lcBytes, 2, 1)) = 255
- lcRet = "UTF-16"
- Case Asc(Left(lcBytes, 1)) = 255 ;
- and Asc(substr(lcBytes, 2, 1)) = 254
- lcRet = "UTF-16"
- Otherwise
- lcRet = "UTF-8"
- EndCase
- EndIf
- Return lcRet
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement