在EXCEL中添加2个文本框的控件,一个为输入,另一个输出 。中间的空格替换成 "--",表示识别成功。
Sub Split()
Dim str_input As String
str_input = Worksheets("sheet1").TextBox_Input.Text
Call split_word(str_input)
Worksheets("sheet1").TextBox_output.Text = str_input
End Sub
Sub split_word(ByRef str_input As String)
Dim str_output As String
Dim one_word As String
Dim space_pos As Integer
space_pos = 0
str_input = Trim(str_input)
While (Len(str_input) > 0)
space_pos = InStr(str_input, " ")
If space_pos = 0 Then
str_output = str_output & " -- " & str_input
str_input = ""
Else
one_word = Mid(str_input, 1, space_pos - 1)
str_output = str_output & " -- " & one_word
str_input = Trim(Mid(str_input, space_pos))
End If
Wend
str_input = str_output
End Sub