A Julia implementation of the Knuth-Morris-Pratt algorithm for string searching.
- Find the first occurrence of a keyword in the text.
- Press ']' in Julia's REPL to enter package mode.
pkg> add https://github.com/closekn/KnuthMorrisPratt.jl
- code
using KnuthMorrisPratt
text = "Hello, world!"
keyword = "world"
pos = KMP_search(text, keyword)
if pos <= length(text)
println("Found : $(pos)")
else
println("Not Found")
end
- output
Found : 8