Win a copy of React Cookbook: Recipes for Mastering the React Framework this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

Problem in a while loop

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 492
Firefox Browser VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It would be helpful if you posted the pattern and text you are using to test this.

Hunter
 
Mah pish
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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





 
Marshal
Posts: 26750
81
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Bartender
Posts: 4568
9
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Mah pish
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.

 
Mah pish
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Matthew Brown
Bartender
Posts: 4568
9
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, you could do something like this:

The key thing is to only call matcher.find() in the loop condition, not anywhere else.
 
Mah pish
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Matthew, It works fine now
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome!
 
Your mind is under my control .... your will is now mine .... read this tiny ad
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic