以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]字符串是否包含数组关键字  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=138280)

--  作者:天一生水
--  发布时间:2019/7/27 11:32:00
--  [求助]字符串是否包含数组关键字
字符串中的关键字“根据.........之规定”,根据个人习惯会有不同的表述,比如:

依照、之规定
依据、规定
依、规定
据、之规定
...

我把上述关键字的组合放入表A的单元格中,每一组合 为一行。
如果字符串包含单元格中的任意一个组合,就显示“true”。
请老师帮助修改一下代码。谢谢!

\'\'\'
Dim str As String = "根据《行政诉讼法》第三条第二款之规定"
Dim lst As New List(of String)
lst = Tables("表A").Current.DataRow.Lines("第一列")
For Each ls As String In lst
    Dim ss() As String = ls.Split("、")
    For i As Integer =  0 To ss.count - 1
        If str.Contains(ss(i)) Then
            msgbox(true)
            Exit For
        End If
    Next
Next


图片点击可在新窗口打开查看此主题相关图片如下:截屏图片.jpg
图片点击可在新窗口打开查看


--  作者:有点蓝
--  发布时间:2019/7/27 11:47:00
--  
\'\'\'
Dim str As String = "根据《行政诉讼法》第三条第二款之规定"
Dim lst As New List(of String)
lst = Tables("表A").Current.DataRow.Lines("第一列")
For Each ls As String In lst
    Dim ss() As String = ls.Split("、")
    Dim p As Boolean = True
    For i As Integer =  0 To ss.count - 1
        If str.Contains(ss(i)) = False Then
            p = False
            Exit For
        End If
    Next
    If p Then
        msgbox(true)
        Exit For
    End If
Next

--  作者:天一生水
--  发布时间:2019/8/9 15:00:00
--  

蓝老师好!

我参照上面的代码,定位Word文档中包含关键字组合的段落。为什么段落存在,弹出的序号不对,序数大了100多。

代码哪里不对,请老师指教!

谢谢!

 

\'\'\'
Dim dlg As new OpenFileDialog
dlg.Filter = "word|*.doc;*.docx"
If dlg.ShowDialog = DialogResult.OK Then
    Dim app As New MSWord.Application
    try
        Dim doc = app.Documents.Open(dlg.FileName)
        Dim count = Doc.Characters.Count
        Dim rng As MSWord.Range = Doc.Range()
        \'msgbox(rng.Text)
        Dim str As String = rng.text
        Dim ary() = str.replace(chr(10), "").split(new Char() {chr(13),chr(11)})      \'清除段落空行
       
        Dim i1 = -1         \'预设原告开始位置
        Dim str1 As String = "原告报告|原告、报告、身份情况"    \'原告开始位置关键字组合
       
        Dim ls As new List(Of String)
        For Each s As String In ary    \'遍历段落
            If s.trim() > "" Then
                ls.add(s)    \'将段落加入集合

                For Each s1 As String In str1.split("|")      \'判断是否包含st1关键字
                    Dim ss1() As String = s1.Split("、")
                    Dim lst1 As New List(of String)           \'关键字新集合
                    lst1.AddRange(ss1)
                    Dim p As Boolean = True
                    For i As Integer =  0 To lst1.count - 1
                        If s.Contains(lst1(i)) = False Then
                            p = False
                            Exit For
                        End If
                    Next
                    If p Then
                        \' msgbox(true)
                        i1 = ls.count-1
                        msgbox(i1)
                        Exit For
                    End If
                Next
               
            End If
        Next
        app.quit
    catch ex As exception
        msgbox(ex.message)
        app.quit
    End try
End If


--  作者:有点蓝
--  发布时间:2019/8/9 15:12:00
--  

自行调试

For Each s As String In ary    \'遍历段落
            If s.trim() > "" Then

output.show(ls.count & " = " & s)

                ls.add(s)    \'将段落加入集合

                For Each s1 As String In str1.split("|")      \'判断是否包含st1关键字

output.show("s1 = " & s1)

                    Dim ss1() As String = s1.Split("、")
                    Dim lst1 As New List(of String)           \'关键字新集合
                    lst1.AddRange(ss1)
                    Dim p As Boolean = True
                    For i As Integer =  0 To lst1.count - 1
                        If s.Contains(lst1(i)) = False Then

output.show("包含 = " & lst1(i))
                            p = False‘表示找到,这里p=false
                            Exit For
                        End If
                    Next

output.show("p = " & p)
                    If p Then \'p=true,这里表示的是没有找到
                        \' msgbox(true)
                        i1 = ls.count-1
                        msgbox(i1)
                        Exit For
                    End If
                Next
                
            End If
        Next