I'm making an app that flashes one word at a time on the screen. These words are currently created by making an array of strings called words[] and splitting up the main string (toRead) into words using split().
I've also made a Sentences class that is created using Breakiterator to split toRead into sentences. I store start and end for each sentence. However these start and end integers are the index of the characters in the toRead string. But my program sets the text by using the words[] array which indexes words.
Ex: One sentence could start at index 0 and end at index 20. (20 character long sentence with variable amount of words). And it may contain 5 words. So words[0] to word[4] contains this sentence.
What I'd like to do is to get the index of the word showing while my app is running, and figure out what sentence that word is in. Then when the "rewind sentence" button is pressed the index changes to the index of the first word in that sentence (or perhaps the sentence before).
I need some help coming up with the algorithm for doing this. I can think of some ways that would be very high in time complexity but I need something more efficient. Maybe using a hash function if necessary.
Edit: I'll try to be more clear.
The user will enter some sort of a string (the use case for my app is an article or a long essay). The string is called toRead. Then I have a function that takes an input of toRead and creates a String[] called words that has all of the words in the toRead string. So the first word is words[0], etc. In my app when you hit the "play" button it cycles through all the words in words[] one at a time, in order of index at a chosen words-per-minute. While this is going on, I'd like my rewind button to be able to know what sentence the user is on, and return to the beginning of that sentence (while continuing to cycle through the words) and if pressed again I'd like it to return to a sentence before that, and if again to a sentence before that, etc.
So far I've been able to split the toRead string into sentences using BreakIterator and a Sentence class that just has a start and end. So basically I have a bunch of Sentence objects with index values for where they begin and end, but these index values are the character numbers and not the word numbers (which is what I'm using to display each word).