简体   繁体   English

VB.NET For循环添加额外的字符

[英]VB.NET For loop adding extra character

I don't really know how to explain the error... CODE: 我真的不知道如何解释该错误...代码:

Public Class AnagramSolver
    Private inputChars() As Char
    Private Sub btnSolveAnagram_Click(sender As Object, e As EventArgs) Handles btnSolveAnagram.Click
        If Not input.Text.Length <= 1 Then
            ReDim inputChars(input.Text.Length - 1)
            For i = 1 To input.Text.Length 'puts each character from string into an array
                inputChars(i - 1) = Mid(input.Text, i, 1)
            Next
        Else
            MsgBox("The length of the anagram must be at least 2")
        End If
    End Sub
End Class

I use a For Next loop to step through a string and put each character into an array. 我使用For Next循环来遍历字符串并将每个字符放入数组中。 But when i'm debugging with the watch window, an extra character is in every element of the array. 但是,当我使用监视窗口进行调试时,数组的每个元素中都有一个额外的字符。 These are the array elements in the watch window. 这些是监视窗口中的数组元素。 inputted string = "james" 输入的字符串=“詹姆斯”

(0) = "j"c
(1) = "a"c
(2) = "m"c
(3) = "e"c
(4) = "s"c

I have no idea where the extra 'c' is coming from. 我不知道多余的“ c”来自哪里。 any help? 有什么帮助吗?

These 'c's aren't a part of the value, it's simply the debugger's represantation of a char . 这些'c'不是值的一部分,只是调试器对char

It prints them out so you know that it's a char "j" , not a string "j" . 它打印出它们,因此您知道它是一个char "j" ,而不是string "j" As such, it has no effect to how your code works. 因此,它对代码的工作方式没有影响。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM