A
A
Amigo20192020-10-16 20:49:58
Java
Amigo2019, 2020-10-16 20:49:58

How to find word/s of char characters in a string of char characters?

Good afternoon!
Sorry for the very stupid question.
But to find a word / a (array of words) from char characters in a string of char characters. The fact is that I tried using String and regular expressions, but somehow it didn’t work out well from separators and options like or (operator).
And I came to the conclusion that only char by char can qualitatively solve the problem, check the string for the presence of words.
but buried himself in an algorithmic problem, it does not work.
There is a string and several arrays of words that are searched for in the string .. something like this.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2020-10-17
@Amigo2019

If you decide head-on, then you simply loop through the elements of the array in which the search is carried out until you meet a character that matches the first character of the searched word, after which you compare the characters in pairs in the nested loop. The complexity is quadratic, but the implementation is elementary. A more performant variant is the Rabin-Karp algorithm . Even better results can be given by the Knuth-Morris-Pratt and Boyer-Moore algorithms .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question