Website Design United States, Website Design California, Website Designing United States, Website Designing California

Manipulating a String using a Byte array. - Visual Basic 6

Take a string, and assign it to a Byte array. Then walk the byte array forwards, and then backwards to demonstrate how to use the Byte array.

When you put a value into the Byte array, it uses the ASCII value of the character, not the character itself.

This sample just uses the Form_Load event to display the results.

Private Sub Form_Load()
Dim sValue As String
Dim t() As Byte 'a byte array
Dim i As Integer
Dim sNewValue As String


sValue = "Hello World" 'Store the original
t = sValue 'Convert the string to a Byte array
sValue = vbNullString 'Empty the contents of the string

'Walk through the Byte array, forwards, skipping every other value
'Every other value is a Null (ASCII value of 0).
For i = 0 To UBound(t) Step 2
sValue = sValue & ChrW$(t(i)) 'Build the result string
Next i

'Same as before, we just walk the array backwards this time
For i = UBound(t) - 1 To -1 Step -2
sNewValue = sNewValue & ChrW$(t(i)) 'Build the result string
Next i

'Print out the results
Debug.Print sValue
Debug.Print sNewValue
End Sub


WEB DESIGN INDIA
42 B Malviya Nagar , New Delhi-110017

Skype: manmeetsi
Email: support.webdesignindia@gmail.com
Tel: 91-011-40502005, 9810067295

 















 


© 2008-2009 dotnet4all.com