字符串可以直接分配给字节数组,反之亦然。请记住,字符串存储在多字节字符集中(请参见下面的备注),因此只有结果数组的所有其他索引才是属于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.PrintChr$(bytes(i)) 'Prints T, e, s, t, i, n, g, . Next Dim reverted As String reverted = bytes 'Direct assignment. Debug.Print reverted 'Prints "Testing."