與位元組陣列的分配

字串可以直接分配給位元組陣列,反之亦然。請記住,字串儲存在多位元組字符集中(請參閱下面的備註),因此只有結果陣列的每個其他索引都將是屬於 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."