Reputation: 669
I am looking for a simple API to return a list of all the indexes where a sequence alignment occurs between a small string and a larger string.
Is there any method in the java or Scala libraries that do this?
Upvotes: 1
Views: 248
Reputation: 10894
No need for kooking further. indexOf does the trick. For one element:
"test" indexOf "es"
res4: Int = 1
For more elements:
scala> List("beer" , "root beer", "bavarian beer" , "a beer bong" ) map (_ indexOf "beer")
res6: List[Int] = List(0, 5, 9, 2)
If you want to use something else it would be best to stick to some standard implementations widely used. For example Apache Commons http://commons.apache.org/proper/commons-lang/ has a good StringUtils package which contains string matching algorithms.
For Boyer-Moore there are myriads of implementations. On Wikipedia you even find a Java implementation: http://en.wikipedia.org/wiki/Boyer%E2%80%93Moore_string_search_algorithm
Upvotes: 1