0

My question is very similar to this one

Java: method to get position of a match in a String?

Except that I will be searching through very long strings (hundreds of megabytes) so I would like for the method to give up after a certain index.

Something like this except with an end index as well. Is there a library that provides this functionality?

Community
  • 1
  • 1
Carlos Bribiescas
  • 4,197
  • 9
  • 35
  • 66
  • 1
    You can do a `substring(0, endIndex)` and then call the `indexOf(match)` on the resulted string or just read how many bytes you need and then try matching. – RP- Sep 10 '14 at 01:17
  • The following is **not** a duplicate. Hopefully it will give you additional ideas. [Fast alernative for String#indexOf(String str)](http://stackoverflow.com/questions/5564610/fast-alernative-for-stringindexofstring-str) – PM 77-1 Sep 10 '14 at 01:20

1 Answers1

0

Ye you can co this in 2 steps.

  1. Get the Substring in which you want to search i.e. from beginning to the endIndex(or Certain index) using subString(0, certainIndex)

  2. Then use indexOf(matchString) to find the location i=of the first occurence of the pattern into the String.

Hitesh Garg
  • 1,211
  • 1
  • 10
  • 21