Skip to content

Latest commit

 

History

History
43 lines (29 loc) · 2.15 KB

how-to-convert-strings-into-an-array-of-bytes.md

File metadata and controls

43 lines (29 loc) · 2.15 KB
description title ms.date helpviewer_keywords ms.assetid
Learn more about: How to: Convert Strings into an Array of Bytes in Visual Basic
How to: Convert Strings into an Array of Bytes
07/20/2015
string conversion [Visual Basic], arrays
arrays [Visual Basic], converting strings to
byte arrays
examples [Visual Basic], string conversion
arrays [Visual Basic], byte arrays
f477d35c-a3fc-4a30-b1d4-cd0d353aae1d

How to: Convert Strings into an Array of Bytes in Visual Basic

This topic shows how to convert a string into an array of bytes.

Example

This example uses the xref:System.Text.Encoding.GetBytes%2A method of the xref:System.Text.Encoding.Unicode%2A?displayProperty=nameWithType encoding class to convert a string into an array of bytes.

[!code-vbVbVbalrStrings#74]

You can choose from several encoding options to convert a string into a byte array:

  • xref:System.Text.Encoding.ASCII%2A?displayProperty=nameWithType: Gets an encoding for the ASCII (7-bit) character set.

  • xref:System.Text.Encoding.BigEndianUnicode%2A?displayProperty=nameWithType: Gets an encoding for the UTF-16 format using the big-endian byte order.

  • xref:System.Text.Encoding.Default%2A?displayProperty=nameWithType: Gets an encoding for the system's current ANSI code page.

  • xref:System.Text.Encoding.Unicode%2A?displayProperty=nameWithType: Gets an encoding for the UTF-16 format using the little-endian byte order.

  • xref:System.Text.Encoding.UTF32%2A?displayProperty=nameWithType: Gets an encoding for the UTF-32 format using the little-endian byte order.

  • xref:System.Text.Encoding.UTF7%2A?displayProperty=nameWithType: Gets an encoding for the UTF-7 format.

  • xref:System.Text.Encoding.UTF8%2A?displayProperty=nameWithType: Gets an encoding for the UTF-8 format.

See also