简体   繁体   English

随机数字不会附加在文本框vb.net中

[英]Random Numbers doesnot append in textbox vb.net

Hello this is something new i discovered today i cant append the Other strings when creating random characters string of 20 chars 您好,这是我今天发现的新内容,当我创建20个字符的随机字符串时,无法追加其他字符串

here is my code 这是我的代码

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

now the output doesnot append second string after those random chars if i take this way 现在,如果我采用这种方式,输出将不会在那些随机字符之后附加第二个字符串

Textbox1.Text = randchars & second & first Textbox1.Text = randchars&第二和第一

output is only randchars not first and second but if i append randchars after both strings it appends what can be the problem ? 输出仅是randchars而不是第一和第二,但是如果我在两个字符串之后都附加randchars,它会附加什么问题?

好的,这可以通过将String Builder替换为Dim rndm()来解决,如Char = New Char(llen){},然后追加到string builder和最后的stringbuilder.tostring

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

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