• Post Reply Bookmark Topic Watch Topic
  • New Topic

JDK1.5 extract string doesn't work  RSS feed

 
Edward Chen
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to extract xml field from a string, the code below is working 1.6, but not working 1.5. Do you know why ? In the 1.5 what is the best way to extract xml field, assuming we will not use third party library.

Thanks

 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please remember that ItDoesntWorkIsUseless. Tell us what exactly is (or isn't) happening. Does it compile? does it run? does it throw and error? Does it give an unexpected result (and what is the actual and expected result?).

You need to TellTheDetails if you really expect to get any help.
 
Edward Chen
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fred rosenberger wrote:Please remember that ItDoesntWorkIsUseless. Tell us what exactly is (or isn't) happening. Does it compile? does it run? does it throw and error? Does it give an unexpected result (and what is the actual and expected result?).
.


In my sample above, the startIdx should be zero, but the return result is negative. The weird thing is, it will work as expected in JDK6.
 
Paul Clapham
Sheriff
Posts: 22844
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, the indexOf method is documented to return -1 if its parameter is not found in the string. So that must be what's happening.

However I don't believe that will happen in the code fragment you posted. Perhaps you could post an SSCCE which exhibits the problem, and not just a fragment?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!