2012-03-17 30 views
0

VBScriptからどのようにGetBytes(System.Text.UTF8Encodingの)を呼び出すのですか?System.Text.UTF8Encoding From VBScript

あなたはcan use the .NET Framework from VBScriptとしてits exposed to COMと書かれていますが、私は良いドキュメンテーション/マニュアルを見つけていません。

+1

時代錯誤、恐竜と人間の映画のスタイル。タイムマシンを戻す[ComVisible]クラスを書くことができます。 –

答えて

3

あなたはVBScriptで同等を探しているなら、あなたは、ADOストリームを使用してそれを行うことができます:

Const adTypeBinary = 1 
Dim adoStr, bytesthroughado 
Set adoStr = CreateObject("Adodb.Stream") 
    adoStr.Charset = "utf-8" 
    adoStr.Open 
    adoStr.WriteText "你好Ğ" 
    adoStr.Position = 0 'reset position 
    adoStr.Type = adTypeBinary 
    adoStr.Position = 3 'skip bom 
    bytesthroughado = adoStr.Read 'get bytes 
    WScript.Echo LenB(bytesthroughado) 'length 
    adoStr.Close 
Set adoStr = Nothing 

それは、VBScriptから(mscorlibから)いくつかの.NETコンポーネントにアクセスすることが可能です。

Dim encoding, bytesthroughdotnet 
Set encoding = CreateObject("System.Text.UTF8Encoding") 
    bytesthroughdotnet = encoding.GetBytes_4("你好Ğ") 'get bytes 
    WScript.Echo LenB(bytesthroughdotnet) 'length 
Set encoding = Nothing 
+0

GetBytes_4で "_4"を使用する方法を知っていますか? – Eugene

+1

@ user389823適切な方法を見つけるまで、接尾辞を増やします。残念ながら、接尾辞の順序は.Netオーバーロードリストと一致しません。誰かが本当に知っているかどうか聞いてみたい。 –

+0

私はhttp://stackoverflow.com/questions/9755263/determining-net-method-suffix-number-in-vbscript-comで質問しました。もう一度ありがとうございます(私はもともと_3までしか行きませんでした)! – Eugene