menu

arrow_back How do I find a word/a of char characters in a string of char characters?

by
1 vote
Good afternoon!
Sorry for the very stupid question.
But to find a word/a(array of words) of char characters in a string of char characters.The thing is that I tried with String and regular expressions, but it did not come out well with delimiters 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 words.
But I stumbled on an algorithmic problem - it doesn't work.
There is a string and several arrays of words that are searched in the string...like this.

8 Comments

What is "char word" and "char string"?
Can you send me the task in its original form without the restatement? I do not understand the final goal to be achieved... Thank you
Sergey Gornostaev , a word of char characters char[] slovo={'w','o','r'.'d'} same with the string
azerphoenix , the regular is not suitable e.g. the word or and operator. or will find twice or combinations (ctoto.ctoto).So regular doesn't really fit, maybe I'm doing something wrong.
azerphoenix ,
without a retelling, no...
There is a code in one of the languages, all characters / words that are there must first be divided into groups (separators identifiers, etc), and then write code that will determine these characters / words / separators in the code, and output what is the character (optional length of the word).
Amigo2019 , use regular expressions to separate words and characters. You can also use the trim() method to remove extra spaces at the beginning and at the end of the word after processing it with a regular expression.
Then you collect all these words and symbols into a collection.
Then you implement a method that takes the text, also splits the words and puts them into a collection. Then use a loop in the loop and check for a match. If it matches, you output a message or something. And if it doesn't, then it doesn't.
That's roughly what I understood from what you wrote. But for a more precise answer, I need details.
Let me correct the wording.
char is not a word but a character

1 Answer

by
 
Best answer
0 votes
If you solve it straightforwardly, you simply loop through the elements of the array in which you are searching until you find a character that matches the first character of the word you are looking for, then in a nested loop you compare the characters in pairs. The complexity is quadratic, but the implementation is elementary. A more productive variant is Rabin-Karp algorithm . Even better results can be obtained with algorithms Knuth-Morris-Pratt и Boyer-Moore .