Ok, let's add some words pertaining to slicing.
block_data[0x1E:0x20]
is a typical slicing of array. It returns a slice of block_data from element 0x1E (14dec) to element 0x20-1 (15dec). We dont' know the type of block_data, though I assume will be bytes. We'll make it in VB.net for any type of array.
I wrote an extension of Array type called slice.
In Visual Studio create a new solution for a library. The following can be compilaed in .net framework and .net core 3.1.
Add a new module as follows:
Imports System.Runtime.CompilerServices
Public Module SliceExtension
<Extension()>
Public Function Slice(Of T)(brr() As T, Optional inizio As Integer = 0, Optional fine As Integer = 0) As T()
Dim Len As Integer = brr.Length
Dim returnArray() As T = {}
If inizio < 0 Then
inizio = Len + inizio
If fine = 0 Then
fine = Len
ElseIf fine < 0 Then
fine = Len + fine
End If
Else
inizio = idx(len:=Len, pos:=inizio)
fine = idx(Len, fine, Len)
End If
Dim elemento As Integer = 0
While (inizio < fine)
Array.Resize(returnArray, returnArray.Length + 1)
returnArray(elemento) = brr(inizio)
elemento += 1
inizio += 1
End While
Return returnArray
End Function
Public Function idx(ByVal len As Integer, pos As Integer, Optional termine As Integer = 0) As Integer
If IsNothing(pos) Then
pos = termine Or 0
ElseIf (pos < 0) Then
pos = Math.Max(len + pos, 0)
ElseIf pos = 0 And termine < 0 Then
pos = len
Else
pos = Math.Min(pos, len)
End If
Return pos
End Function
End Module
Compile. It will create a dll in .bin folder of the project path.
In the same solution create either a desktop or console application to test the extension.
Add a reference to the newly created dll.
Add a Module and paste as follows:
Imports SliceClass.SliceExtension
Module Program
Sub Main()
Dim arr() As String = {"10", "20", "30", "40", "50", "60", "70"}
Dim retarr() As Object = arr.Slice(-3, -1)
Console.WriteLine(retarr.ToString)
End Sub
End Module
Usage: Array.Slice(start, stop)
Please see here for more explanation. Please note the extension does not support step.