944,066 Members | Top Members by Rank

Ad:
Jun 1st, 2006
0

Unicode and Strings

Expand Post »
Given the following two code snippets, how come I get different output?
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Sub test() Dim str As String Dim b() As Byte str = "hello" b() = str str = "" For i = LBound(b) To UBound(b) str = str & b(i) & " " Next i Debug.Print str End Sub
The above produces the following output:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. 104 0 101 0 108 0 108 0 111 0
second procedure:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Sub test2() Dim str As String Dim b() As Byte str = "hello" b() = StrConv(str, vbUnicode) str = "" For i = LBound(b) To UBound(b) str = str & b(i) & " " Next i Debug.Print str End Sub
Which produces this output:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. 104 0 0 0 101 0 0 0 108 0 0 0 108 0 0 0 111 0 0 0
My question is: why the additional zeroes from the second procedure? Assigning a string to a byte array fills the byte array with the unicode characters, and I thought this was essentially what the StrConv function did (with vbUnicode option). Can anyone settle my curiosity? Thanks for any/all replies! Richard
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
RichardSchollar is offline Offline
2 posts
since Jun 2006
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Jun 2nd, 2006
0

Re: Unicode and Strings

Comatose - many thanks for the links. The last one was exceptionally helpful. That has sorted out a problem I was seriously confused by. Thanks again!Richard
Reputation Points: 10
Solved Threads: 0
Newbie Poster
RichardSchollar is offline Offline
2 posts
since Jun 2006
Jun 2nd, 2006
0

Re: Unicode and Strings

You're Welcome!
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: changing menu control
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: question





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC