Convert Byte to Char

  • Thread starter Thread starter John Smith
  • Start date Start date
J

John Smith

Hello,

Suppose I have the following C# code which I want to convert to VB:

for (int i = 0; i < nFieldLength; i++)
Console.Write((char) sValue);

sValue is a byte [] array.

The problem is the typecast which I can't find an equivalent for in VB. I
tried using CChar() and CType() but neither of them seemed to work. Instead
the compiler said it can't convert Byte to Char.

Thanks in advance.

-- John
 
Hi,

Take a look at chr(svalue(i))
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vafctChr.asp

Ken
------------------
Hello,

Suppose I have the following C# code which I want to convert to VB:

for (int i = 0; i < nFieldLength; i++)
Console.Write((char) sValue);

sValue is a byte [] array.

The problem is the typecast which I can't find an equivalent for in VB. I
tried using CChar() and CType() but neither of them seemed to work. Instead
the compiler said it can't convert Byte to Char.

Thanks in advance.

-- John
 
John Smith said:
The problem is the typecast which I can't find an equivalent for in VB. I
tried using CChar() and CType() but neither of them seemed to work.
Instead
the compiler said it can't convert Byte to Char.

'CChar', 'Chr', 'ChrW', 'Convert.ToChar', ...
 
John Smith said:
Hello,

Suppose I have the following C# code which I want to convert to VB:

for (int i = 0; i < nFieldLength; i++)
Console.Write((char) sValue);

sValue is a byte [] array.

The problem is the typecast which I can't find an equivalent for in VB. I
tried using CChar() and CType() but neither of them seemed to work.
Instead
the compiler said it can't convert Byte to Char.

Thanks in advance.

-- John


Dim s As String = "Hello World!"
Dim bytes As Byte() = System.Text.ASCIIEncoding.ASCII.GetBytes(s)
Dim output As String = System.Text.ASCIIEncoding.ASCII.GetString(bytes)
Console.WriteLine(output)

Mythran
 
Back
Top