need to get lines from textfile with string count >

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • alter
    New Member
    • Feb 2014
    • 1

    need to get lines from textfile with string count >

    Have textfile, need to search all file, find what "top=x" dublicates and get all these lines.
    The line that InStr(TextLine, "top=x") > 1

    example:
    <fontspec id="9">
    <text top="89" left="65">25123 8</text>
    <text top="125" left="281">2014-02-13</text>
    <text top="125" left="282">2014-02-13</text>
    <text top="126" left="283">2014-02-13</text>
    <text top="126" left="284">2014-02-13</text>

    Needed:
    get line that string value count > 2

    Result should be:
    <text top="125" left="281">2014-02-13</text>
    <text top="125" left="282">2014-02-13</text>
    <text top="126" left="283">2014-02-13</text>
    <text top="126" left="284">2014-02-13</text>
  • Guido Geurs
    Recognized Expert Contributor
    • Oct 2009
    • 767

    #2
    Split the text on "vbnewline" in an array.
    Run through the lines and isolate those who have the value.
    See also attachment

    Code:
    '§ Text1= original text
    '§ Text2= isolated Text
    '§ TextIsolate has the value for the condition
    '§ (VALUE if isolating on the value of the string)
    '§ (LENGTH if isolating on the length of the string)
    '§ ComSplit isolates the text
    '§ ComClear clears the Text2 box
    
    Option Explicit
    
    
    Private Sub ComClear_Click()
       Text2.Text = ""
    End Sub
    
    Private Sub ComSplit_Click()
    Dim ARRLINES() As String '§ array with lines
    Dim ARRLINESidx As Integer
    Dim LINEstring As String '§ string of a line
    Dim STARTofVALUE As Integer '§ first quote in the line
    Dim ENDofVALUE As Integer '§ second quote in the line
       '§ split into lines
       ARRLINES = Split(Text1.Text, vbNewLine)
       '§ run through the lines
       For ARRLINESidx = LBound(ARRLINES) To UBound(ARRLINES)
          LINEstring = ARRLINES(ARRLINESidx)
          '§ if it is a valid line
          If Left(LINEstring, 5) = "<text" Then
             '§ if it has the string condition
             STARTofVALUE = InStr(LINEstring, """") + 1
             ENDofVALUE = InStr(STARTofVALUE + 1, LINEstring, """")
    
    '§ working with VALUES
    '         If Val(Mid(LINEstring, STARTofVALUE, ENDofVALUE - STARTofVALUE)) = Val(TextIsolate.Text) Then
                
    '§ working with LENGTH
             If Len(Mid(LINEstring, STARTofVALUE, ENDofVALUE - STARTofVALUE)) > Val(TextIsolate.Text) Then
                
                Text2 = Text2 & LINEstring & vbNewLine
             End If
          End If
       Next
    End Sub
    Attached Files

    Comment

    Working...