随机数不会附加在textbox vb.net中

时间:2016-01-08 22:58:01

标签: vb.net

你好这是我今天发现的新东西,在创建20个字符的随机字符串时,我无法附加其他字符串

这是我的代码

Const llen As Integer = 20 ' total 20 chars

Dim cp() As Integer = {48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90}
Dim ch As Integer
Dim r As System.Random = New System.Random()

Dim rndm() As Char = New Char(llen) {}

For i As Integer = 0 To llen - 1
    ch = cp(r.Next(0, cp.Length))
    rndm(i) = Chr(ch)
Next

Dim randchars As String = rndm

Dim first As String = "CUSTOM1"

Dim second As String = "CUSTOM2"

Textbox1.Text = first & randchars & second

现在输出不会在那些随机字符之后附加第二个字符串,如果我采取这种方式

Textbox1.Text = randchars&第二&第一

输出只是randchars而不是第一和第二 但如果我在两个字符串之后附加randchars,它会附加可能出现的问题吗?

1 个答案:

答案 0 :(得分:-1)

好的家伙可以修复String Builder取代Dim rndm()作为Char = New Char(llen){}然后追加到字符串构建器,最后是stringbuilder.tostring