System.Text.UTF8Encoding From VBScript

How do you call GetBytes (from System.Text.UTF8Encoding) from VBScript?

You can use the .NET Framework from VBScript as its COM , but I haven't found any good documentation / tutorials.

0


source to share


1 answer


If you're looking for an equivalent in VBScript, you can do it with Ado Stream:

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

      



Access to some .Net components (from mscorlib) from VBScript.

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

      

+3


source







All Articles