Get character from BYTE value

  • Thread starter Thread starter Alain Dekker
  • Start date Start date
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
 
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)
 
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.
 
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.
 
Back
Top