ソース掲示板




すべてから検索

キーワード   条件 表示 現行ログ 過去ログ トピックス 名前 本文
VBScript 上の SHIFT_JIS データを各種キャラクタセットのテキスト出力
日時: 2018/01/27 21:40
名前: lightbox



変換は全てメモリ上で処理します。

VBScript の中に埋め込んだデータはファイルとしては Shift_JIS です。
VBScript のインタープリタの内部的には Unicode ですが、何も考えなければ
出力されたデータは Shift_JIS になってしまいます。

これを 5 種類のキャラクタセットとして意図的に出力します

1) SHIFT_JIS
2) UNICODE
3) EUC-JP
4) UTF8
5) UTF8N

※ UTF8N が少し特殊です

  charset_write.wsf
拡張子:
<JOB>
<SCRIPT
	language="VBScript"
	src="http://lightbox.in.coocan.jp/laylaClass.vbs">
</SCRIPT>

<SCRIPT language=VBScript>
' ***********************************************************
' 処理開始
' ***********************************************************
Call laylaFunctionTarget( "http://lightbox.in.coocan.jp/" )
Call laylaLoadFunction( "baseFunction.vbs" )

' Csript.exe で実行を強制
Crun

' 元となる shift_jis の文字列
strShiftJis = GetInline("shift_jis")

' このディレクトリ
strDir = ScriptDir()

' ファイルシステムオブジェクト作成
GetFso

' 出力パス
strPath1 = strDir & "\sjis.txt"
strPath2 = strDir & "\unicode.txt"
strPath3 = strDir & "\ujis.txt"
strPath4 = strDir & "\utf8.txt"
strPath5 = strDir & "\utf8n.txt"

' ファイルシステムオブジェクトで、sjis と unicode
Call PutTextFile( strPath1, strShiftJis )
Call PutTextFileUnicode( strPath2, strShiftJis )

' キャラクタセット変換用の Stream オブジェクト
Set Stream = Wscript.CreateObject("ADODB.Stream")
Set Stream2 = Wscript.CreateObject("ADODB.Stream")

' 開く
Stream.Open
Stream2.Open
' 二つ目はバイナリ専用
Stream2.Type = 1

Stream.Charset = "euc-jp"
Stream.WriteText strShiftJis
Stream.SaveToFile strPath3, 2

' 先頭に移動
Stream.Position = 0
Stream.Charset = "utf-8"
Stream.WriteText strShiftJis
Stream.SaveToFile strPath4, 2

' バイナリにコピー
Stream.CopyTo Stream2

' 一つ目もバイナリにする為、いったん閉じる
Stream.Close
' 再度開いてバイナリにする
Stream.Open
Stream.Type = 1

' バイナリを読んでバイナリに書く
Stream2.Position = 0
Stream2.Read(3)
Do while not Stream2.EOS
	Stream.Write Stream2.Read(16)
Loop

' utn-8n
Stream.SaveToFile strPath5, 2


' 閉じる
Stream2.Close
Stream.Close


print "処理が終了しました"
print ""

Wscript.Quit

</SCRIPT>

<RESOURCE id="shift_jis">
<![CDATA[
ここは、VBScript なので shift_jis になります。
必要に応じてキャラクタセットを変更します
]]>
</RESOURCE>

</JOB>
メンテナンス


日時: 2018/01/27 21:40
名前: lightbox