将位字符串数组转换为字节数组

时间:2019-06-26 18:59:14

标签: vb.net reporting-services

我有以下二进制字符串(实际上是一个位数组) “ 1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,0”

我要转换为字节数组。 对于仅接受字节数组的嵌入式报表代码功能,我需要此功能。我已经从powershell转换了此功能。

我找到了,但这是C#

string source = "1,1,1,0,0";

 byte[] result = source
   .Split(',')
   .Select(item => byte.Parse(item))
   .ToArray();

这在报表构建器中不起作用(“选择”不是“ System.Array”的成员。)

Dim source As String = "1,1,1,0,0"
Dim result As Byte() = source.Split(","c).[Select](Function(item) Byte.Parse(item)).ToArray()

如果我按照建议添加System.Linq,我仍然会收到错误消息: “选择”不是“ Linq”的成员。

Dim source As String() = "1,1,1,0,0".Split(","c)
Dim result As Byte() = System.Linq.Select(Function(source) Byte.Parse(source)).ToArray()

1 个答案:

答案 0 :(得分:0)

更仔细地研究函数之后,我意识到输入可以是任何数组,因此我将数组的类型修改为字符串并相应地更新了我的输入。坦克大家试图帮助。

功能

Function GetSQLProductKey(ByVal astrBinaryKey As String(), ByVal intVersion As Integer) As String
    Dim achrKeyChars As Char() = {"B", "C", "D", "F", "G", "H", "J", "K", "M", "P", "Q", "R", "T", "V", "W", "X", "Y", "2", "3", "4", "6", "7", "8", "9"}
    Dim strSQLProductKey As String
    Dim iastrBinaryKey As Long
    Dim iachrKeyChars As Long
    Dim iastrBinaryKeyOuterLoop As Long
    Dim iastrBinaryKeyInnerLoop As Long
    Try
        If (intVersion >= 11) Then
            iastrBinaryKey = 0
        Else
            iastrBinaryKey = 52
        End If
        For iastrBinaryKeyOuterLoop = 24 To 0 Step -1
            iachrKeyChars = 0
            For iastrBinaryKeyInnerLoop = 14 To 0 Step -1
                iachrKeyChars = iachrKeyChars * 256 Xor astrBinaryKey(iastrBinaryKeyInnerLoop + iastrBinaryKey)
                astrBinaryKey(iastrBinaryKeyInnerLoop + iastrBinaryKey) = Math.Truncate(iachrKeyChars / 24)
                iachrKeyChars = iachrKeyChars Mod 24
            Next iastrBinaryKeyInnerLoop
            strSQLProductKey = achrKeyChars(iachrKeyChars) + strSQLProductKey
            If (iastrBinaryKeyOuterLoop Mod 5) = 0 And iastrBinaryKeyOuterLoop <> 0 Then
                strSQLProductKey = "-" + strSQLProductKey
            End If
        Next iastrBinaryKeyOuterLoop
    Catch
        strSQLProductKey = "Cannot decode product key."
    End Try
    GetSQLProductKey = strSQLProductKey
End Function

函数调用SSRS

Code.GetSQLProductKey(Split(Replace(Fields!ProductKey.Value, " ",""), ","), Left(Fields!Version.Value, 2))