0
点赞
收藏
分享

微信扫一扫

Word分词功能


哈喽,手机边亲爱的你好呀!

今天要给大家分享一个“分开”示例。

假设我们现在提供给大家一长段的文字,需要从这长段的文字中提取出词语,要求不用太高,不需要非常的精准,当看到这个需求时,感觉无从下手,不知道该怎么来操作,直到遇到了word的一个分词的功能。

分词就是将连续的字序列按照一定的规范重新组合成词序列的过程。在英文中,单词之间会以空格作为分割符,将词与词之间进行分割,但是对于中文,没有一个显式的分割符。我们接下去看一下这个东西该怎么做。

Word分词功能_Text

01、创建窗体

我们在窗体上放两个文本框,一个用来输入文字,一个用来输出

Word分词功能_access_02

Word分词功能_Text

02、添加代码

接下去我们来添加一下代码

Private Sub btnOK_Click()
    Dim sentence As String
    Dim words As String
    Dim WordApp As Object
    If IsNull(Me.txt文字) Then
        MsgBox "请输入内容。", vbExclamation
        Me.txt文字.SetFocus
        Exit Sub
    End If
    sentence = Me.txt文字
    words = ""
    Set WordApp = CreateObject("Word.Application")
    WordApp.Documents.Add
    WordApp.Selection.TypeText Text:=sentence
    WordApp.Selection.HomeKey
    Do
        WordApp.Selection.MoveRight Unit:=2, Count:=1, Extend:=1
        If WordApp.Selection.Text = vbCr Then Exit Do
        words = words & WordApp.Selection.Text & ";"
        WordApp.Selection.MoveRight Unit:=1, Count:=1
    Loop
    WordApp.Quit SaveChanges:=0
    Set WordApp = Nothing
    Me.txt分词 = words
    End
End Sub

Word分词功能_Text

03、运行测试

输入一段文字后,然后运行测试。

Word分词功能_vba_05

好了,今天的分享就到这里!

举报

相关推荐

0 条评论