PC Review


Reply
Thread Tools Rate Thread

Convert Byte to Char

 
 
John Smith
Guest
Posts: n/a
 
      23rd Nov 2004
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[i]);

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


 
Reply With Quote
 
 
 
 
Ken Tucker [MVP]
Guest
Posts: n/a
 
      23rd Nov 2004
Hi,

Take a look at chr(svalue(i))
http://msdn.microsoft.com/library/de...l/vafctChr.asp

Ken
------------------
"John Smith" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
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[i]);

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



 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      23rd Nov 2004
John,

Dim a as char = chrw(65)
dim b as byte = ascw("A")

For me are the convert functions one of the things which I like very much
from VBNet.

http://msdn.microsoft.com/library/de...conversion.asp

http://support.microsoft.com/default...b;en-us;145745

I hope this helps?

Cor

"John Smith" <(E-Mail Removed)>
....
> 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[i]);
>
> 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
>
>



 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      23rd Nov 2004
"John Smith" <(E-Mail Removed)> schrieb:
> 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', ...

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

 
Reply With Quote
 
Mythran
Guest
Posts: n/a
 
      23rd Nov 2004

"John Smith" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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[i]);
>
> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
convert the byte to a unsigned char puzzlecracker Microsoft C# .NET 3 23rd Feb 2009 01:26 AM
How to convert an unmanaged unsigned char* buffer into a byte [] a BartMan Microsoft VC .NET 2 9th Jun 2008 02:47 PM
how to convert a char array(byte[]) to a string variable? David Microsoft C# .NET 3 17th Mar 2006 02:27 AM
Convert String or char[] to byte[] Marius Cabas Microsoft C# .NET 2 12th Nov 2004 01:13 PM
Re: How to convert a char of a string to single-byte character Michael Giagnocavo [MVP] Microsoft Dot NET Framework 6 23rd Jul 2003 03:26 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:39 AM.