gpt4 book ai didi

vb.net - 将 VB6 代码片段转换为 VB.NET

转载 作者:行者123 更新时间:2023-12-01 15:04:16 25 4
gpt4 key购买 nike

我很难将这段代码转换为 VB.NET

Function DecryptPassword(ByVal s As String) As String
Dim i As Integer
Dim sPass As String = s.Trim()

For i = 1 To Len(sPass)
If Asc(Mid$(sPass, i, 1)) - 5 < 124 Then

'this line throws "type char $ does not match declared data type char"
Mid$(sPass, i, 1) = Chr$(Asc(Mid$(sPass, i, 1)) - 5)

Else
Mid$(sPass, i, 1) = Mid$(sPass, i, 1)
End If
Next
DecryptPassword = UCase(sPass) ' Convert UserPassword to UpperCase
End Function

它在 VB6 中运行良好,但在我使用 VB.Net 时会抛出错误。

最佳答案

试试这个版本:

Function DecryptPassword(ByVal s As String) As String

If String.IsNullOrEmpty(s) Then
Return String.Empty
End If

Dim sbPass As New System.Text.StringBuilder(s.Length)

For Each oCharacter As Char In s.Trim
If Asc(oCharacter) - 5 < 124 Then
sbPass.Append(Convert.ToChar(Asc(oCharacter) - 5))
Else
sbPass.Append(oCharacter)
End If
Next
Return sbPass.ToString.ToUpper
End Function

关于vb.net - 将 VB6 代码片段转换为 VB.NET,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8854950/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com