以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助]关于字符串分段  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=96012)

--  作者:2900819580
--  发布时间:2017/2/10 14:46:00
--  [求助]关于字符串分段


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

 

 关闭标志 is null and 完成入仓 = \'FALSE\' and 组装车间_完成 = \'FALSE\' and( 产品名称 like \'%777%\' or 产品名称 like \'%8301%\' )

 

如何将上面这段文字分段,如下所示。

 

 


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

--  作者:有点色
--  发布时间:2017/2/10 15:23:00
--  

\'\'\'...
Dim str As String = "关闭标志 is null and 完成入仓 = \'FALSE\' and 组装车间_完成 = \'FALSE\' and ( 产品名称 like \'%777%\' or 产品名称 like \'%8301%\')"
str = str.ToLower
Dim keys() As String = {" is ", " = ", " like "}
dim flts as new list(Of string)
Do While True
    Dim sidx As Integer = 0
    Dim eidx1 As Integer = str.IndexOf(" and ")
    Dim eidx2 As Integer = str.IndexOf(" or ")
    Dim eidx As Integer = -1
    If eidx1>=0 AndAlso eidx2>=0 Then
        eidx = math.Min(eidx1+1, eidx2)
    ElseIf eidx1>=0 Then
        eidx = eidx1+1
    ElseIf eidx2>=0 Then
        eidx = eidx2
    End If
    If eidx >= 0 Then
        Dim temp As String = str.SubString(sidx, eidx)
        output.show(temp)
        flts.add(temp.trim)
        str = str.SubString(eidx+4)
    Else
        Dim temp As String = str.SubString(sidx)
        output.show(temp)
        flts.add(temp.trim)
        Exit Do
    End If
Loop
output.show("------------------")
For Each flt As String In flts
    For Each key As String In keys
        Dim idx As Integer = flt.IndexOf(key)
        If idx >= 0 Then
            output.show(flt.SubString(0, idx))
            output.show(key)
            output.show(flt.SubString(idx+key.length))
            Exit For
        End If
    Next
Next


--  作者:有点蓝
--  发布时间:2017/2/10 20:50:00
--  
Dim s As String="关闭标志 is null and 完成入仓 = \'FALSE\' and 组装车间_完成 = \'FALSE\' and ( 产品名称 like \'%777%\' or 产品名称 like \'%8301%\')"
Dim p As String = "(?=is|\\=|like)"
Dim p2 As String = "(?=and|or)"
Dim r As New System.Text.RegularExpressions.Regex(p2)
Dim str = r.Split(s)
For Each a As String In str
    Output.Show(a)
Next
Output.Show("-------------------")
r = New System.Text.RegularExpressions.Regex(p)
For Each a As String In str
    Dim s2() As String = r.Split(a)
    For Each b As String In s2
        Output.Show(b)
    Next
Next