File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
Head First Android
this week in the
Java in General
Getting un-Expected Results From String IndexOf Method
Joined: Nov 16, 2004
Nov 12, 2010 06:18:34
If 'iConn.getItemSpocno().trim()' is a blank
and '(iConn.getSpocFAIExclusionList()' = S070,S110,S120,S130 why does the following still return a 0 value?
Joined: Aug 12, 2008
Nov 12, 2010 08:03:46
please post the output of running this code
Joined: Oct 13, 2005
Nov 12, 2010 08:26:21
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.
Joined: Oct 18, 2010
Nov 12, 2010 08:53:33
If you will search blank i.e. "" in any String then it index will always be 0.
I agree. Here's the link:
subject: Getting un-Expected Results From String IndexOf Method
Extract an Email From a String literal
q from abhilash mock exam on strings.
Why is "String".trim() not equal to " String ".trim()
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015