I am writing a code that would take a string which has blank lines between sentences. i need to find a certain word and print out all the next words following it till it reaches a blank line. for instance: test1 as the input in the following string:
Welcome to JavaRanch! I added code tags to your post to make it easier to read.
In th line p = text.indexOf(intIndex,old_p), both intIndex and old_p are defined as ints, but there is no String.indexOf() method that works on two ints. What were you going for there? I would think you'd want to look for a line separator.
Line separators are platform specific though. You'd have to know what the String was using. I'd actually prefer a StringReader, wrapped in a LineNumberReader for this job, but a StringTokenizer could work. So could just searching for line separators.
Joined: May 12, 2011
Thanks for the replies, But i still cant work it out. I gave up the other method, Now i am trying to find the word that comes between the other words (test1 and test 5). any help?
OK, in that case, you know how to get the index of "test1" and the index of "test5", and you know how to get a substring. It seems like you're done. If you need to break the substring into words, then something like substring.split("\\s") should do the job for you.