Re: Strings and Unicode in VBA
- From: "Karl E. Peterson" <karl@xxxxxxxx>
- Date: Fri, 2 Jun 2006 09:41:38 -0700
RichardSchollar wrote:
Thanks Karl - yes, it is basically doing the conversion twice.
In a way of speaking, that's the perceptual result, yep. <g>
Thanks for the help!
You bet.
--
Working without a .NET?
http://classicvb.org/
Karl E. Peterson wrote:
Hi Richard --
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).
Calling StrConv (with vbUnicode) on a string that's *already*
Unicode, you're telling it to consider every byte to be an ANSI
character code, so it's changing the "normal" 00 bytes to 00 00.
Make sense?
Later... Karl
--
Working without a .NET?
http://classicvb.org/
richardschollar@xxxxxxxxxxx wrote:
Apologies for a dual post (in Excel.Programming too) but not getting
any response there:
Given the following two code snippets, how come I get different
output?
Code:
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:
Code:
104 0 101 0 108 0 108 0 111 0
second procedure:
Code:
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:
Code:
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!
Best regards
Richard
.
- References:
- Strings and Unicode in VBA
- From: richardschollar
- Re: Strings and Unicode in VBA
- From: Karl E. Peterson
- Re: Strings and Unicode in VBA
- From: RichardSchollar
- Strings and Unicode in VBA
- Prev by Date: Re: Strings and Unicode in VBA
- Next by Date: Re: VBA project migration Office 2003 to Office 2000
- Previous by thread: Re: Strings and Unicode in VBA
- Next by thread: DB2 Runstats
- Index(es):
Relevant Pages
|