In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article focuses on the "vbs implementation of unicode and ascii coding conversion method tutorial", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor to take you to learn the "vbs implementation of unicode and ascii coding conversion method tutorial"!
1. Copy a Unicode File to an ANSI File
WiToAnsi.vbs file:
The copy code is as follows:
'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
Called in batch:
The copy code is as follows:
Cscript WiToAnsi.vbs [path to Unicode file] [path to ANSI file]
II. Copy an ANSI File to an Unicode File
You only need to adjust the way OpenTextFile and CreateTextFile are opened.
III. Reference
Http://msdn.microsoft.com/en-us/library/aa368046%28VS.85%29.aspx
IV. The use of OpenTextFile and CreateTextFile
CreateTextFile method
Creates the specified file and returns a TextStream object that can be used to read or write to the created file.
The copy code is as follows:
Object.CreateTextFile (filename [, overwrite [, unicode]])
Parameters.
Object
Required. Expected the name of the FileSystemObject or Folder object.
Filename
Required. A string expression that indicates the file to create.
Overwrite
Optional. The Boolean value indicates whether existing files can be overwritten. If the file can be overwritten, the value is True;. If the file cannot be overwritten, the value is False. If you omit this value, you cannot overwrite an existing file.
Unicode
Optional. The Boolean value indicates whether the file is created in Unicode or ASCII file format. This value is True; if the file is created in Unicode file format, and False if the file is created in ASCII file format. If you omit this section, it is assumed that the ASCII file is created.
OpenTextFile method
Opens the specified file and returns a TextStream object that can be read, written, or appended to the file.
The copy code is as follows:
Object.OpenTextFile (filename [, iomode [, create [, format]])
Parameters.
Object
Required. Expected the name of the FileSystemObject object.
Filename
Required. A string expression indicating the name of the file to open.
Iomode
Optional. The input / output mode is one of the following three constants: ForReading,ForWriting, or ForAppending.
Create
Optional. The Boolean value indicating whether a new file can be created if the specified filename does not exist. True when new files are allowed to be created, False otherwise. The default is False.
Format
Optional. One of the three Tristate values indicating the format in which to open the file. If you omit this parameter, the file is opened in ASCII format.
Set up
The iomode parameter can be one of the following settings:
The numeric description ForReading1 opens the file in read-only mode. You cannot write to this file. ForWriting2 opens the file in write-only mode. This file cannot be read. ForAppending8 opens the file and writes at the end of the file.
The format parameter can be one of the following settings:
The constant value description TristateUseDefault-2 opens the file in the system default format. TristateTrue-1 opens the file in Unicode format. TristateFalse0 opens the file in ASCII format. At this point, I believe that you have a deeper understanding of the "vbs implementation of unicode and ascii coding conversion method tutorial", might as well come to the actual operation! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.