• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting un-Expected Results From String IndexOf Method

 
Steve Dyke
Ranch Hand
Posts: 1619
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If 'iConn.getItemSpocno().trim()' is a blank string and '(iConn.getSpocFAIExclusionList()' = S070,S110,S120,S130 why does the following still return a 0 value?

 
Muhammad Safwat
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please post the output of running this code
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because an empty String can be found at the 0 position.

Imagine: if you add nothing to the beginning of that String, it won't change. Therefore it is the same as having an empty String at its very beginning, so you get 0 as the index.
 
himanshu.harish agrawal
Ranch Hand
Posts: 47
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Steve,

If you will search blank i.e. "" in any String then it index will always be 0.

Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic