我有两个文本框,只能包含大写字母,还有一个存储无符号整数的变量。比方说,例如5.我怎样才能使包含随机文本的TextBox分成5个字母的组?
例如:ABCDEFGHIJKLMNOPQRSTUVWXYZ
成为:ABCDE FGHIJ KLMNO PQRST UVWXY Z
如果文本被用户替换,我需要实时完成此操作。我也不能使用多个文本框,每个文本框允许n个字符,因为我应该格式化的文本可以无限长。
答案 0 :(得分:0)
每次Textbox.Text
更改时,您都可以使用此方法:
Private Sub Textbox1_TextChanged(sender As Object, e As EventArgs) Handles Textbox1.TextChanged
Dim sentence As String = Textbox1.Text
Dim pairedChars as Integer = 5
If pairedChars <= sentence.Length Then
'First remove all spaces from the last time
sentence.Replace(" ", "")
'Add spaces at every 5th place in the string
For i = 1 to (sentence.Length) / pairedChars
sentence = sentence.Insert(i * pairedChars + (i - 1), " ")
Next
End If
End Sub