问题描述
考虑:
char [] chararray = txt1.Text;
我们如何在 Visual Basic 6.0 中做同样的事情?
How we do the same in Visual Basic 6.0?
推荐答案
这取决于你最终想要做什么.
That depends on what you eventually want to do.
例如,您可以在 VB6 中执行此操作:
You can, for example, do this in VB6:
Dim b() As Byte
b = Text1.Text
这样 b
数组将被调整大小以保存来自 "string"
的 Unicode 数据——但是每个字符将被分成两个字节,这可能不是你想要什么.此技巧仅适用于 Byte
.
That way the b
array will be resized to hold the Unicode data from "string"
-- but then each character will be split across two bytes which is probably not what you want. This trick only works with Byte
.
你也可以这样做:
Dim b() As Byte
b = StrConv(Text1.Text, vbFromUnicode)
现在每个字母将占用一个字节,但扩展字符将消失.仅当当前系统代码页包含所需字符时才执行此操作.
Each letter will now occupy one byte, but the extended characters will be gone. Only do this if the current system code page contains the required characters.
您可以手动将字符复制到数组中:
You can copy the characters manually to an array:
Dim s() As String, i As Long
ReDim s(1 To Len(Text1.Text))
For i = 1 To UBound(s)
s(i) = Mid$(Text1.Text, i, 1)
Next
或者你甚至可以完全避免创建一个数组,因为 Mid
也可以作为一个索引操作符来改变一个字符,而不需要复制或分配任何东西:
Or you can even avoid creating an array at all, becase Mid
also serves as an indexer operator that changes a character in place, without copying or allocating anything:
Dim s As String
s = Text1.Text
Mid$(s, 3, 1) = "!"
这篇关于Visual Basic 6.0 中的字符数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!