婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > vbs實現unicode和ascii編碼轉換

vbs實現unicode和ascii編碼轉換

熱門標簽:除了地圖標注還有這種生意嗎 如何用機器人進行電銷 百度地圖標注點距離代碼 佛山真人電銷機器人廠家 神行者美術館地圖標注 哪里有便宜的地圖標注公司 地圖標注政府哪個部門管 齊齊哈爾高德地圖標注店 東營快遞外呼系統

一、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的使用

CreateTextFile 方法

創建指定文件并返回 TextStream 對象,該對象可用于讀或寫創建的文件。

復制代碼 代碼如下:

object.CreateTextFile(filename[, overwrite[, unicode]])

參數

object

必選項。應為 FileSystemObject 或 Folder 對象的名稱。

filename

必選項。字符串表達式,指明要創建的文件。

overwrite

可選項。Boolean 值指明是否可以覆蓋現有文件。如果可覆蓋文件,該值為 True;如果不能覆蓋文件,則該值為 False 。如果省略該值,則不能覆蓋現有文件。

unicode

可選項。Boolean 值指明是否以 Unicode 或 ASCII 文件格式創建文件。如果以 Unicode 文件格式創建文件,則該值為 True;如果以 ASCII 文件格式創建文件,則該值為 False。如果省略此部分,則假定創建 ASCII 文件。

OpenTextFile 方法

打開指定的文件并返回一個 TextStream 對象,可以讀取、寫入此對象或將其追加到文件。

復制代碼 代碼如下:

object.OpenTextFile(filename[, iomode[, create[, format]]])

參數

object

必選項。應為 FileSystemObject 對象的名稱。

filename

必選項。字符串表達式,指明要打開的文件名稱。

iomode

可選項。輸入/輸出模式,是下列三個常數之一:ForReading,ForWriting,或 ForAppending。

create

可選項。Boolean 值,指出當指定的 filename 不存在時是否能夠創建新文件。允許創建新文件時為 True,否則為 False。默認值為 False。

format

可選項。三個 Tristate 值之一,指出以何種格式打開文件。若忽略此參數,則文件以 ASCII 格式打開。

設置

iomode 參數可為下列設置之一:

描述
ForReading 1 以只讀模式打開文件。不能對此文件進行寫操作。
ForWriting 2 以只寫方式打開文件。不能對此文件進行讀操作。
ForAppending 8 打開文件并在文件末尾進行寫操作。

format 參數可為下列設置之一:

常數 描述
TristateUseDefault -2 以系統默認格式打開文件。
TristateTrue -1 以 Unicode 格式打開文件。
TristateFalse  0 以 ASCII 格式打開文件。

您可能感興趣的文章:
  • PHP中正則表達式對UNICODE字符碼的匹配方法
  • java實現漢字轉unicode與漢字轉16進制實例
  • 正則表達式之 Unicode 匹配特殊字符

標簽:邢臺 湖州 海口 四平 銅川 鶴壁 西安 文山

巨人網絡通訊聲明:本文標題《vbs實現unicode和ascii編碼轉換》,本文關鍵詞  vbs,實現,unicode,和,ascii,編碼,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《vbs實現unicode和ascii編碼轉換》相關的同類信息!
  • 本頁收集關于vbs實現unicode和ascii編碼轉換的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 谷城县| 吐鲁番市| 开阳县| 南康市| 德江县| 四平市| 仁寿县| 吕梁市| 新宾| 蓬安县| 普兰店市| 台北市| 吴桥县| 绵阳市| 察隅县| 汝城县| 永吉县| 务川| 雷州市| 利津县| 柳林县| 抚宁县| 深州市| 定襄县| 湟中县| 黎川县| 宁陵县| 涟水县| 渑池县| 合作市| 德庆县| 即墨市| 金溪县| 东阳市| 凤台县| 江达县| 象州县| 宁夏| 微山县| 凤山市| 剑川县|