How do I get the index of a single word (represents in a char array) which can be found in a paragraph (again represents in a char array).
the char represents the word
char word[] = new char[]{'w','o','r','d'};
and here's the paragraph
char para[] = new char[]{'f','g','q','z','y','i','o','p','w','o','r','d'};
I would like to get the index of the first letter in this case 8th. I used binary search by when sorting the words get scrambled.
Thanks.
A bit inefficient theoretically, but rather practical and simple:
int position = new String(paragraph).indexOf(new String(word));
If you want to understand how this works - check the static int indexOf(..)
method of java.lang.String
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With