将 JScript 转换为 VB.NET - 问题
我正在尝试将一些用 JScript 编写的函数转换为 VB.NET(我正在将经典 ASP 页面移植到 ASP.NET),但由于我对 JScript 不太熟悉而遇到了问题。我在 VB.NET 中正确转换函数声明时遇到问题。在我转换后的代码中,VS2008 给我一个错误,说“数组边界不能在类型标识符中指定”。我不知道如何修改函数声明以返回数组,但也像 JScript 声明一样接受数组作为输入。有什么想法吗?我这样做是错误的吗?
提前致谢。
这是原始的 JScript 函数之一:
function binl2byt(binarray)
{
var hex_tab = "0123456789abcdef";
var bytarray = new Array(binarray.length * 4);
var str = "";
for(var i = 0; i < binarray.length * 4; i++)
{
bytarray[i] = (binarray[i>>2] >> ((i%4)*8+4) & 0xF) << 4 | binarray[i>>2] >> ((i%4)*8) & 0xF;
}
return bytarray;
}
这是到目前为止我在 VB.NET 中拥有的函数:
Public Function binl2byt() As Array(byval binarray as array)
Dim hex_tab As String = "0123456789abcdef"
Dim bytarray() As Byte
Dim str As String = ""
For I As Integer = 0 To (bytarray.Length * 4) Step 1
bytarray(I) = ((binarray(I >> 2) >> ((I Mod (4)) * 8 + 4) & Oxf) << 4) Or (binarray(I >> 2) >> ((I Mod (4) * 8) & OxF))
Next
Return bytarray
End Function
I'm trying to convert some functions written in JScript to VB.NET (I'm porting a classic ASP page to ASP.NET) and having issues as I'm not very familiar with JScript. I'm having issues with converting even the function declaration properly in VB.NET. In my converted code VS2008 is giving me an error saying "Array bounds can not be specified in type identifiers". I don't know how to modify my function declaration to return an Array but ALSO accept an array as input as the JScript declaration does. Any ideas? Am I approaching this wrong?
Thanks in advance.
Here is one of the original JScript functions:
function binl2byt(binarray)
{
var hex_tab = "0123456789abcdef";
var bytarray = new Array(binarray.length * 4);
var str = "";
for(var i = 0; i < binarray.length * 4; i++)
{
bytarray[i] = (binarray[i>>2] >> ((i%4)*8+4) & 0xF) << 4 | binarray[i>>2] >> ((i%4)*8) & 0xF;
}
return bytarray;
}
Here is what I have in VB.NET so far:
Public Function binl2byt() As Array(byval binarray as array)
Dim hex_tab As String = "0123456789abcdef"
Dim bytarray() As Byte
Dim str As String = ""
For I As Integer = 0 To (bytarray.Length * 4) Step 1
bytarray(I) = ((binarray(I >> 2) >> ((I Mod (4)) * 8 + 4) & Oxf) << 4) Or (binarray(I >> 2) >> ((I Mod (4) * 8) & OxF))
Next
Return bytarray
End Function
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不需要这个函数,.NET 中已经为您提供了该函数。
其中 Bytes 是您的字节数组。
There is no need for this function, it is already there in .NET for you.
Where Bytes is your byte array.