Advertisement
Guest User

Get Unicode Encoding

a guest
Aug 2nd, 2018
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Function GetUnicodeEncoding(lcFilename As String)
  2. Local lcRet, lnHandle
  3.  
  4.     * -- Encoding       Representation (hexadecimal)    Representation (dec)   
  5.     * -- UTF-8[t 1]     EF BB BF                        239 187 191                
  6.     * -- UTF-16 (BE)    FE FF                           254 255
  7.     * -- UTF-16 (LE)    FF FE                           255 254
  8.  
  9.     lcRet = "FILEOPENERROR"
  10.  
  11.     lnHandle = Fopen(lcFilename)
  12.    
  13.     If lnHandle > 0
  14.        
  15.         =Fseek(lnHandle, 0, 0)
  16.         lcBytes = Fread(lnHandle, 3)
  17.         Fclose(lnHandle)
  18.        
  19.         Do Case
  20.            
  21.             Case Asc(Left(lcBytes, 1)) = 239 ;
  22.                 and Asc(substr(lcBytes, 2, 1)) = 187 ;
  23.                     and Asc(right(lcBytes, 1)) = 191 ;
  24.            
  25.                 lcRet = "UTF-8"
  26.            
  27.             Case Asc(Left(lcBytes, 1)) = 254 ;
  28.                 and Asc(substr(lcBytes, 2, 1)) = 255
  29.            
  30.                 lcRet = "UTF-16"
  31.  
  32.             Case Asc(Left(lcBytes, 1)) = 255 ;
  33.                 and Asc(substr(lcBytes, 2, 1)) = 254
  34.  
  35.                 lcRet = "UTF-16"
  36.  
  37.         Otherwise
  38.                 lcRet = "UTF-8"            
  39.         EndCase
  40.                    
  41.     EndIf
  42.  
  43. Return lcRet
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement