以下为代码,采用textbox空间获得输入字符的长度,并通过button_click触发
设置了判断功能,判断当前截取的字符元素长度是否与采集长度一致,如果不一致则舍弃该采集结果,避免存储重复的数据
Sub button_click()
Dim input_name,part_output As String
Dim input_name_part(0 To 99, 0 To 99) As String
Dim i, j, name_len As Integer
StartTime = Timer
input_name = Trim(TextBox1.Text)
name_len = Len(input_name)
i = 1
j = 1
Do
input_name_part(i, j) = Mid(input_name, j, i)
If Len(input_name_part(i, j)) <> Val(i) Then
input_name_part(i, j) = ""
End If
j = j + 1
If j = name_len + 1 Then
i = i + 1
j = 1
End If
If i = name_len + 1 Then
Exit Do
End If
Loop
i = 1
j = 1
Do
part_output = part_output & input_name_part(i, j) & Chr(13)
j = j + 1
If input_name_part(i, j) = "" Then
i = i + 1
j = 1
End If
If i = name_len + 1 Then
Exit Do
End If
Loop
Documents.Add.Content.Text = part_output
MsgBox Timer - StartTime
End Sub
写在末尾,当然也可预先在字符之间设置分隔符,然后通过split函数直接获取。