有没有人有办法将字符串从JS转换为escape()
版本?我会对单个命令或任何类型的函数感到满意。
答案 0 :(得分:1)
Microsoft.JScript.dll
Microsoft.JScript.GlobalObject.escape
功能进行编码。这是一个相同的过程,无论您使用VB.Net,C#还是其他.Net语言。他们都必须支持string
/ String
。
或者,这里有一些代码可以做同样的事情,反映和转换它。
Public Shared Function Escape(str As String) As String
Dim str2 As String = "0123456789ABCDEF"
Dim length As Integer = str.Length
Dim builder As New StringBuilder(length * 2)
Dim num3 As Integer = -1
While System.Threading.Interlocked.Increment(num3) < length
Dim ch As Char = str(num3)
Dim num2 As Integer = ch
If (((&H41 > num2) OrElse (num2 > 90)) AndAlso _
((&H61 > num2) OrElse (num2 > &H7a))) AndAlso _
((&H30 > num2) OrElse (num2 > &H39)) Then
Select Case ch
Case "@"C, "*"C, "_"C, "+"C, "-"C, "."C, "/"C
GoTo Label_0125
End Select
builder.Append("%"C)
If num2 < &H100 Then
builder.Append(str2(num2 / &H10))
ch = str2(num2 Mod &H10)
Else
builder.Append("u"C)
builder.Append(str2((num2 >> 12) Mod &H10))
builder.Append(str2((num2 >> 8) Mod &H10))
builder.Append(str2((num2 >> 4) Mod &H10))
ch = str2(num2 Mod &H10)
End If
End If
Label_0125:
builder.Append(ch)
End While
Return builder.ToString()
End Function