国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > VBScript > 正文

vbs實現unicode和ascii編碼轉換

2019-10-26 18:08:05
字體:
來源:轉載
供稿:網友

一、Copy a Unicode File to an ANSI File

WiToAnsi.vbs文件:

復制代碼 代碼如下:

' Utility to rewrite a Unicode text file as an ANSI text file
' For use with Windows Scripting Host, CScript.exe or WScript.exe
' Copyright (c) 1999, Microsoft Corporation
'
Option Explicit

' FileSystemObject.CreateTextFile and FileSystemObject.OpenTextFile
Const OpenAsASCII   = 0
Const OpenAsUnicode = -1

' FileSystemObject.CreateTextFile
Const OverwriteIfExist = -1
Const FailIfExist      = 0

' FileSystemObject.OpenTextFile
Const OpenAsDefault    = -2
Const CreateIfNotExist = -1
Const FailIfNotExist   = 0
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8

Dim argCount:argCount = Wscript.Arguments.Count
If argCount > 0 Then If InStr(1, Wscript.Arguments(0), "?", vbTextCompare) > 0 Then argCount = 0
If (argCount = 0) Then
    Wscript.Echo "Utility to copy Unicode text file to an ANSI text file." &_
        vbNewLine & "The 1st argument is the Unicode text file to read" &_
        vbNewLine & "The 2nd argument is the ANSI text file to write" &_
        vbNewLine & "If the 2nd argument is omitted, the Unicode file will be replaced"
    Wscript.Quit 1
End If

Dim inFile, outFile, inStream, outStream, inLine, FileSys, WshShell
If argCount > 1 Then
    outFile = Wscript.Arguments(1)
    inFile  = Wscript.Arguments(0)
Else
    outFile = Wscript.Arguments(0)
    inFile  = outFile & ".tmp"
    Set WshShell = Wscript.CreateObject("Wscript.Shell")
    WshShell.Run "cmd.exe /c copy " & outFile & " " & inFile, 0, True
End If

Set FileSys = CreateObject("Scripting.FileSystemObject")
Set inStream  = FileSys.OpenTextFile(inFile, ForReading, FailIfNotExist, OpenAsDefault)
Set outStream = FileSys.CreateTextFile(outFile, OverwriteIfExist, OpenAsASCII)
Do
    inLine = inStream.ReadLine
    outStream.WriteLine inLine
Loop Until inStream.AtEndOfStream
inStream.Close
outStream.Close
If argCount = 1 Then WshShell.Run "cmd.exe /c del " & inFile, 0

批處理中調用:

復制代碼 代碼如下:

cscript WiToAnsi.vbs [path to Unicode file][path to ANSI file]

二、Copy a ANSI File to an Unicode File

只需對OpenTextFile和CreateTextFile的打開方式做調整即可。

三、參考

http://msdn.microsoft.com/en-us/library/aa368046%28VS.85%29.aspx

四、OpenTextFile和CreateTextFile的使用

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 松潘县| 加查县| 闸北区| 固安县| 昌宁县| 巴林右旗| 开化县| 江津市| 衡山县| 承德县| 舟山市| 蓝山县| 长海县| 华亭县| 临洮县| 怀宁县| 元阳县| 莒南县| 乌鲁木齐市| 遂溪县| 邵阳市| 沙坪坝区| 乌拉特中旗| 冀州市| 阜宁县| 赤壁市| 海门市| 瑞金市| 进贤县| 名山县| 澄迈县| 七台河市| 双城市| 永年县| 罗城| 许昌市| 南靖县| 商都县| 银川市| 阿拉尔市| 高台县|