Forums Register Login

Problem in a while loop

+Pie Number of slices to send: Send
hi Guy,
I have a code that reads a text file and searches for certain words with certain patterns and returns them. It works fine. The only problem is that it doesnt return the first word, Although all the words have the same pattern. this is the while code:


Any help would be appreciated.
+Pie Number of slices to send: Send
It would be helpful if you posted the pattern and text you are using to test this.

Hunter
+Pie Number of slices to send: Send
Thanks Hunter, This is the code:



and the string testing would be something like this:


the code return:
test-3333-4444

it skips the first one which is :
test-1111-2222





+Pie Number of slices to send: Send
 

Mah pish wrote:and the string testing would be something like this:



That isn't what I would expect as the result of


Not unless the method is really badly named, that is. I suggest you look at that a little more carefully. I know nothing about this StringUtils class but it's possible that the result of that substringBetween call is

and not

as you seem to be assuming.
2
+Pie Number of slices to send: Send
The first one matches fine - on line 38. But you then throw the match away. It's only the second and subsequent matches that are being output in the while loop.
+Pie Number of slices to send: Send
 

Paul Clapham wrote:Sorry , i'd forgotten some parts of the html code

Mah pish wrote:and the string testing would be something like this:



That isn't what I would expect as the result of


Not unless the method is really badly named, that is. I suggest you look at that a little more carefully. I know nothing about this StringUtils class but it's possible that the result of that substringBetween call is

and not

as you seem to be assuming.

 
+Pie Number of slices to send: Send
So what should be changed in the loop?

Matthew Brown wrote:The first one matches fine - on line 38. But you then throw the match away. It's only the second and subsequent matches that are being output in the while loop.

 
2
+Pie Number of slices to send: Send
Well, you could do something like this:

The key thing is to only call matcher.find() in the loop condition, not anywhere else.
+Pie Number of slices to send: Send
Thanks Matthew, It works fine now
+Pie Number of slices to send: Send
You're welcome!
Evil is afoot. But this tiny ad is just an ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1204 times.
Similar Threads
Escaping Stuff in a String
Array out of bound; arrays handling
Searching is messed up
Insert into Doubly LinkedList
response.sendRedirect Immediately In Struts
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 06:10:14.