Daily Archives: November 5, 2020

VB.NET || How To Convert A String To Byte Array & Byte Array To String Using VB.NET

The following is a module with functions which demonstrates how to convert a string to a byte array and a byte array to a string using VB.NET.


1. String To Byte Array

The example below demonstrates the use of ‘Utils.GetBytes‘ to convert a string to a byte array. The optional parameter allows to specify the encoding.


2. Byte Array To String

The example below demonstrates the use of ‘Utils.GetString‘ to convert a byte array to a string. The optional parameter allows to specify the encoding.


3. Utils Namespace

The following is the Utils Namespace. Include this in your project to start using!


4. More Examples

Below are more examples demonstrating the use of the ‘Utils‘ Namespace. Don’t forget to include the module when running the examples!

QUICK NOTES:
The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.

VB.NET || How To Save, Open & Read File As A Byte Array & Memory Stream Using VB.NET

The following is a module with functions which demonstrates how to save, open and read a file as a byte array and memory stream using VB.NET.


1. Read File – Byte Array

The example below demonstrates the use of ‘Utils.ReadFile‘ to read a file as a byte array.


2. Read File – Memory Stream

The example below demonstrates the use of ‘Utils.ReadFile‘ to read a file as a memory stream.


3. Save File – Byte Array

The example below demonstrates the use of ‘Utils.SaveFile‘ to save the contents of a byte array to a file.


4. Save File – Memory Stream

The example below demonstrates the use of ‘Utils.SaveFile‘ to save the contents of a memory stream to a file.


5. Utils Namespace

The following is the Utils Namespace. Include this in your project to start using!


6. More Examples

Below are more examples demonstrating the use of the ‘Utils‘ Namespace. Don’t forget to include the module when running the examples!

QUICK NOTES:
The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.