Get character from BYTE value

A

Alain Dekker

Simple question this:

If I receive a list of byte values, eg. [104][101][108][108][111], this
would be "hello" as a string. Is there a simple command (part of the .NET
library) to convert from [104] into "h"? Using VB.NET 2003.

Thanks,
Alain
 
F

Family Tree Mike

Simple question this:

If I receive a list of byte values, eg. [104][101][108][108][111], this
would be "hello" as a string. Is there a simple command (part of the .NET
library) to convert from [104] into "h"? Using VB.NET 2003.

Thanks,
Alain

I think this is what you want:

Dim values() As Byte = {104, 101, 108, 108, 111}
Dim s As String = UTF8Encoding.ASCII.GetString(values)
Console.WriteLine(s)
 
H

Herfried K. Wagner [MVP]

Mike --

Am 12.02.2010 01:59, schrieb Family Tree Mike:
If I receive a list of byte values, eg. [104][101][108][108][111], this
would be "hello" as a string. Is there a simple command (part of the .NET
library) to convert from [104] into "h"? Using VB.NET 2003.

I think this is what you want:

Dim values() As Byte = {104, 101, 108, 108, 111}
Dim s As String = UTF8Encoding.ASCII.GetString(values)

I'd write 'Encoding.ASCII' instead of 'UTF8Encoding.ASCII', which will
work too but which semantically doesn't make much sense.
 
A

Alain Dekker

Thanks, yes the System.Encoding.ASCII method turned out to be the one I
wanted. UNICODE takes some getting used to! Its all good stuff, but when
you're writing applications that never need the UNICODE, its a complication
that sometimes I wish could be "switched off".

Thanks again,
Alain


Herfried K. Wagner said:
Mike --

Am 12.02.2010 01:59, schrieb Family Tree Mike:
If I receive a list of byte values, eg. [104][101][108][108][111], this
would be "hello" as a string. Is there a simple command (part of the
.NET
library) to convert from [104] into "h"? Using VB.NET 2003.

I think this is what you want:

Dim values() As Byte = {104, 101, 108, 108, 111}
Dim s As String = UTF8Encoding.ASCII.GetString(values)

I'd write 'Encoding.ASCII' instead of 'UTF8Encoding.ASCII', which will
work too but which semantically doesn't make much sense.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top