Results 1 to 11 of 11

Thread: Extracting Specific Text from a string is slow

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2009
    Location
    Japan
    Posts
    87

    Extracting Specific Text from a string is slow

    I have a text file I'm trying to pull specific data from to make a report in excel and am wanting to know if my code can be improved or if I have something wrong. If it's apparent to anyone that I should be doing something else could you tell me please. This code does work but, very slow. These reports take up to 20 minutes for about 100 files so I am wanting to decrease the time somehow. I have attached the whole sub in a text file, it's about 900 lines long so don't think I should post all of it. This is one part that seems to take the longest:

    Partial code that reads the text into a string, then each line is read to find whether it holds the data or not. Inside this while loop, I am checking numerous lines to see what they hold and extract specific items. First I verify it's a interface by checking for "line protocol".
    Code:
    Dim str As StreamReader = File.OpenText(filefound)
                        While (str.Peek <> -1)
                            If txtLine.Contains("line protocol") = True Then 'Found an interface,
    'Then a snippet that grabs a few more things, these three items are always on a single line. Then I place into excel cells.
    Code:
    'Get MTU, BW and DLY
                            If txtLine.Contains("MTU") = True And txtLine.Contains("BW") = True And txtLine.Contains("DLY") = True Then
                                PosX = txtLine.IndexOf("MTU") + 4                           ' MTU 1500 bytes, BW 1000000 Kbit, DLY 10 usec, 
                                PosY = txtLine.IndexOf("bytes,")                            '     ^   ^
                                PosY = PosY - PosX
                                MTU = txtLine.Substring(PosX, PosY)
                                oSheet.Cells(oRow, 6).value = MTU
    
                                PosX = txtLine.IndexOf("BW", 1) + 3                            'MTU 1500 bytes, BW 1000000 Kbit, DLY 10 usec, 
                                PosY = txtLine.IndexOf("bit", 1)
                                PosY = PosY - PosX - 2
                                BW = txtLine.Substring(PosX, PosY)
                                oSheet.Cells(oRow, 7).value = BW
    
                                PosX = txtLine.IndexOf("DLY") + 3
                                PosY = txtLine.IndexOf("usec")
                                DLY = txtLine.Substring(PosX, PosY - PosX)
    
                                oSheet.Cells(oRow, 8).value = DLY
                            End If

    Here is another snippet that grabs a single value from within this same readline loop.
    Code:
    'Get Description
                            If txtLine.Contains("Description") = True Then
                                txtLine.Trim()
                                Desc = txtLine.Replace("Description", "")
                                Desc = Trim(Desc)
                                Desc.Replace(":", "")
                                oSheet.Cells(oRow, 5).Value = Desc.Replace(":", "")
                            End If

    Very appreciative of any help/suggestions. Thanks.
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width