与字节数组的分配

字符串可以直接分配给字节数组,反之亦然。请记住,字符串存储在多字节字符集中(请参阅下面的备注),因此只有结果数组的每个其他索引都将是属于 ASCII 范围内的字符部分。

Dim bytes() As Byte
Dim example As String

example = "Testing."
bytes = example             'Direct assignment.

'Loop through the characters. Step 2 is used due to wide encoding.
Dim i As Long
For i = LBound(bytes) To UBound(bytes) Step 2
    Debug.Print Chr$(bytes(i))  'Prints T, e, s, t, i, n, g, .
Next

Dim reverted As String
reverted = bytes            'Direct assignment.
Debug.Print reverted        'Prints "Testing."