我正在 Visual Basic 中将数字 Ascii 值转换为它们各自的字符,但它失败了:
这里 pth 中给出的值已经被转换为 Ascii 值,所以你在变量 textval 变量中看到的是路径的 ascii equivalint
Dim i As Integer
Dim dec As String
Dim original As Integer
Dim sentence As String
Dim inter As String
Dim pth =" c:\TESTER:\JESTER\MESTER "
textval="32 99 58 92 84 69 83 84 69 82 58 92 74 69 83 84 69 82 92 77 69 83 84 69 82 32"
textval = Trim(textval)
'Dim ts() As String = Split(textval)
Dim words As String() = textval.Split(New Char() {" "c})
Label1.Text = words(0) + words(1) + words(2)
original = Int(ts(2))
上面的代码没有为 words(2) 第二个字符是 COLON ":" 或 ascii 数字 2961 提供任何值
我怎样才能纠正这个问题并使这个问题更普遍以接受任何特殊字符?
在此先感谢您的宝贵回答。
您不会将整数值转换为字符。你必须使用Chr
或ChrW
解决这个问题。请参阅以下代码示例:
解决方案使用Chr
:
Dim textValues1 As String = "32 99 58 92 84 69 83 84 69 82 58 92 74 69 83 84 69 82 92 77 69 83 84 69 82 32"
textValues1 = textValues1.Trim
Dim textWords1 As String() = textValues1.Split(New Char() {" "c})
Dim strValue1 As String = ""
For i As Integer = 0 To UBound(textWords1)
Dim numValue As Integer = 0
If Integer.TryParse(textWords1(i), numValue) Then
strValue1 &= Chr(CInt(numValue))
End If
Next
Debug.Print(strValue1) 'output: c:\TESTER:\JESTER\MESTER
解决方案使用ChrW
:
Dim textValues2 As String = "32 99 58 92 84 69 83 84 69 82 58 92 74 69 83 84 69 82 92 77 69 83 84 69 82 32"
textValues2 = textValues2.Trim
Dim textWords2() As String = textValues2.Split(New Char() {" "c})
Dim strValue2 As String = ""
For j As Integer = 0 To UBound(textWords2)
Dim numValue As Integer = 0
If Integer.TryParse(textWords2(j), numValue) Then
strValue2 &= ChrW(CInt(numValue))
End If
Next
Debug.Print(strValue2) 'output: c:\TESTER:\JESTER\MESTER
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句