Character Array in Visual Basic 6.0

Consider:

char [] chararray = txt1.Text;

How do we do the same in Visual Basic 6.0?

+3
source share
5 answers

It depends on what you ultimately want to do.

You can, for example, do this in VB6:

Dim b() As Byte
b = Text1.Text

That way, the size of the array bwill be resized to store Unicode data from "string", but then each character will be split into two bytes, which is probably not the one you want. This trick only works with Byte.


You can also do this:

Dim b() As Byte
b = StrConv(Text1.Text, vbFromUnicode)

Each letter will now take one byte, but extended characters will disappear. Only do this if the current system code page contains the required characters.


You can copy the characters manually into 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 , , :

Dim s As String
s = Text1.Text

Mid$(s, 3, 1) = "!"
+8

VB6, .

, :

Dim chararray(Len(txt1.Text) - 1) As String
For i = 1 to Len(txt1.Text)
  chararray(i - 1) = Mid(txt1.Text, i, 1)
Next

Edit:

, :

' Copy the value of the proeprty to a local variable
Dim text as String = txt1.Text
' Loop over the length of the string
For i = 1 to Len(text)
  ' Check the value of a character
  If Mid(text, i, 1) = " " Then
    ' Replace a character
    Mid(textx, i, 1) = "*"
  End If
Next
+4

VB6 String, :

Dim x As String
x = Text1.Text

VB6.

, , Byte ( VB char), StrConv Unicode -, @GSerg.

+2
source

String To Array :

Public Function str2Array(xString As String) As String()
Dim tmpArray() As String
Dim tmpchar As String

' /* For Each Character In The String */
For I = 1 To Len(xString)

    ' /* Retrieve The Character */
    tmpchar = Mid(xString, I, 1)
    ' /* Push It Into The Temporary Array */
    spush tmpArray, tmpchar
Next I

' /* Return The Array To The Calling Procedure */
str2Array = tmpArray
End Function
0
source

You can get the UNICODE value of each character in a string this way:

Dim chararray (1 To Len (txt1.Text)) How long

For i = 1 To Len (txt1.Text) chararray (i) = ASCW (Mid (Text1.Text, i, 1)) Next

0
source

Source: https://habr.com/ru/post/1767147/


All Articles