+ Reply to Thread
Results 1 to 2 of 2

Thread: Convert ASCII to UTF-8

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    24

    Convert ASCII to UTF-8

    Hi , i would like a vb script to convert ASCII format to UTF-8 format , i`d be appreciated if you helped me and thanks in advance .

  2. #2
    Junior Member
    Join Date
    Jan 2012
    Posts
    45
    Here is how you can convert from ASCII to UTF-8

    Code:
     Option Explicit
    
     Dim objFSO, originalFile, GeneratedFile
    
     originalFile = WScript.ScriptName
    
     Set objFSO = CreateObject( "Scripting.FileSystemObject" )
     GeneratedFile = objFSO.GetBaseName( originalFile ) & "_utf8.txt"
     Set objFSO = Nothing
    
     UTF8 originalFile, GeneratedFile
    
    
     Function UTF8( myFileIn, myFileOut )
    
         Dim objStream
    
         ' Valid Charset values for ADODB.Stream
    
         Const CdoBIG5        = "big5"
         Const CdoEUC_JP      = "euc-jp"
         Const CdoEUC_KR      = "euc-kr"
         Const CdoGB2312      = "gb2312"
         Const CdoISO_2022_JP = "iso-2022-jp"
         Const CdoISO_2022_KR = "iso-2022-kr"
         Const CdoISO_8859_1  = "iso-8859-1"
         Const CdoISO_8859_2  = "iso-8859-2"
         Const CdoISO_8859_3  = "iso-8859-3"
         Const CdoISO_8859_4  = "iso-8859-4"
         Const CdoISO_8859_5  = "iso-8859-5"
         Const CdoISO_8859_6  = "iso-8859-6"
         Const CdoISO_8859_7  = "iso-8859-7"
         Const CdoISO_8859_8  = "iso-8859-8"
         Const CdoISO_8859_9  = "iso-8859-9"
         Const cdoKOI8_R      = "koi8-r"
         Const cdoShift_JIS   = "shift-jis"
         Const CdoUS_ASCII    = "us-ascii"
         Const CdoUTF_7       = "utf-7"
         Const CdoUTF_8       = "utf-8"
    
         ' ADODB.Stream file I/O constants
    
         Const adTypeBinary          = 1
         Const adTypeText            = 2
         Const adSaveCreateNotExist  = 1
         Const adSaveCreateOverWrite = 2
    
         On Error Resume Next
         
         Set objStream = CreateObject( "ADODB.Stream" )
         objStream.Open
         objStream.Type = adTypeText
         objStream.Position = 0
         objStream.Charset = CdoUTF_8
         objStream.LoadFromFile myFileIn
         objStream.SaveToFile myFileOut, adSaveCreateOverWrite
         objStream.Close
         Set objStream = Nothing
         
         If Err Then
             UTF8 = False
         Else
             UTF8 = True
         End If
         
         On Error Goto 0
     End Function

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts