将VB6函数转换为C# [英] Convert VB6 function to C#
问题描述
大家好,
我需要将vb函数转换为c#,但我不是VB的专家,事实上我从未编写过VB之前。有没有人知道任何可以将VB函数转换为c#的工具?我试过搜索互联网,但我似乎找不到任何支持VB6的东西。
如果我们想知道我需要转换为c#的功能,它看起来像这样:
Hi All,
I need to convert a vb function to c# but i'm not an expert in VB and matter of fact is i have never coded in VB before. Does anyone know of any tools that would let convert a VB function into c#? I have tried search the internet but i can't seem to find anything that supports VB6.
If anyonwe wondering what function i need to convert to c# it looks like this:
Function Base64Decode(ByVal base64String)
'rfc1521
'1999 Antonin Foller, Motobit Software, http://Motobit.cz
Const Base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
Dim dataLength, sOut, groupBegin
'remove white spaces, If any
base64String = Replace(base64String, vbCrLf, "")
base64String = Replace(base64String, vbTab, "")
base64String = Replace(base64String, " ", "")
'The source must consists from groups with Len of 4 chars
dataLength = Len(base64String)
If dataLength Mod 4 <> 0 Then
Err.Raise 1, "Base64Decode", "Bad Base64 string."
Exit Function
End If
' Now decode each group:
For groupBegin = 1 To dataLength Step 4
Dim numDataBytes, CharCounter, thisChar, thisData, nGroup, pOut
' Each data group encodes up To 3 actual bytes.
numDataBytes = 3
nGroup = 0
For CharCounter = 0 To 3
' Convert each character into 6 bits of data, And add it To
' an integer For temporary storage. If a character is a '=', there
' is one fewer data byte. (There can only be a maximum of 2 '=' In
' the whole string.)
thisChar = Mid(base64String, groupBegin + CharCounter, 1)
If thisChar = "=" Then
numDataBytes = numDataBytes - 1
thisData = 0
Else
thisData = InStr(1, Base64, thisChar, vbBinaryCompare) - 1
End If
If thisData = -1 Then
Err.Raise 2, "Base64Decode", "Bad character In Base64 string."
Exit Function
End If
nGroup = 64 * nGroup + thisData
Next
'Hex splits the long To 6 groups with 4 bits
nGroup = Hex(nGroup)
'Add leading zeros
nGroup = String(6 - Len(nGroup), "0") & nGroup
'Convert the 3 byte hex integer (6 chars) To 3 characters
pOut = Chr(CByte("&H" & Mid(nGroup, 1, 2))) + _
Chr(CByte("&H" & Mid(nGroup, 3, 2))) + _
Chr(CByte("&H" & Mid(nGroup, 5, 2)))
'add numDataBytes characters To out string
sOut = sOut & Left(pOut, numDataBytes)
Next
Base64Decode = sOut
End Function
如果有人可以,我真的很感激帮助我以正确的方式指导我。
我尝试过:
我在网上搜索过,我遇到过这些工具,其中一些是帮助,有些则不是。
Vb [ ^ ]<这个很不错,遗憾的是它缺少我需要转换的功能
Code Converter [ ^ ]<<我在这个问题上遇到了很多错误。
谢谢
I would really appreciate if someone could help on direct me in the right way.
What I have tried:
I have searched the internet and i have come across these tools which some have been a help and others not so.
Vb [^] < this one is pretty good unfortunately its missing the function that i need to convert
Code Converter[^] << I'm getting a way lot of errors with this one.
Thank you
推荐答案
你可以只是跳过转换所有代码使用一行代码来做同样的事情:
Convert.FromBase64String Method(String)(System) [ ^ ]
You could just skip converting all that code use a single line of code to do the same thing:
Convert.FromBase64String Method (String) (System)[^]
这篇关于将VB6函数转换为C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!