if len(text1.text) <4 then select case len(text1.text) case 1 text1.text = text1.text & " " case 2 text2.text=text2.text & " " case 3 text1.text=text1.text & " " end select end if
你判断字符的长度,如果不到4位的话就把字符串加上空格 dim strname as string =txt_name.Text if txt_name.Text.Length = 4 strname=txt_name.Text else if txt_name.Text.Length=3 strname+=" " else if txt_name.Text.Length=2 strname+=" " esle MsgBox("你输入的名字不准确.") End if
6楼的效率比较高啦,呵呵!! Private Sub cmdAddSpace_Click() Dim str As String str = "888" If Len(str) < 6 Then str = str + Space(6 - Len(str)) End If MsgBox "the length of '" & str & "' is " & Len(str) & "" End Sub