Fastest way to find strings in a file

后端 未结 5 1300
耶瑟儿~
耶瑟儿~ 2021-01-18 23:04

I have a log file that is not more than 10KB (File size can go up to 2 MB max) and I want to find if atleast one group of these strings occurs in the files. These strings w

5条回答
  •  一向
    一向 (楼主)
    2021-01-18 23:39

    You don't have much of a choice with text files when it comes to efficiency. The easiest way would definitely be to loop through each line of data. When you grab a line in a string, split it on the spaces. Then match those words to your words until you find a match. Then do whatever you need.

    I don't know how to do it in c# but in vb it would be something like...

    Dim yourString as string
    Dim words as string()
    Do While objReader.Peek() <> -1
       yourString = objReader.ReadLine()
       words = yourString.split(" ")
       For Each word in words()
          If Myword = word Then
             do stuff
          End If
       Next
    Loop
    

    Hope that helps

提交回复
热议问题