Unicode and Strings

Thread Solved

Join Date: Jun 2006
Posts: 2
Reputation: RichardSchollar is an unknown quantity at this point 
Solved Threads: 0
RichardSchollar RichardSchollar is offline Offline
Newbie Poster

Unicode and Strings

 
0
  #1
Jun 1st, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer
Join Date: Jun 2006
Posts: 2
Reputation: RichardSchollar is an unknown quantity at this point 
Solved Threads: 0
RichardSchollar RichardSchollar is offline Offline
Newbie Poster

Re: Unicode and Strings

 
0
  #3
Jun 2nd, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: Unicode and Strings

 
0
  #4
Jun 2nd, 2006
You're Welcome!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC