Forums Register Login

Evaluating String indexof

+Pie Number of slices to send: Send
I have the following code why if value is "" does indexof get evaluated to 0:


spoc exclusion list = ('S070','S100','S110','S120','S130','S150','S200')

+Pie Number of slices to send: Send
It's because the first place in the string "S070" which matches a zero-length string is at the beginning, i.e. position zero. If that's a little too obscure for you, then have a look at the API documentation for the startsWith() method of String, which says

"Returns true if the character sequence represented by the argument is a prefix of the substring of this object starting at index toffset; false otherwise."

And if you look at it that way, then "" is indeed the first zero characters of "S070".
+Pie Number of slices to send: Send
Is it indexOf that gets evaluated to 0, or the result of that last line? Because the last line says that if indexOf returns anything larger than -1, 100 should be used and otherwise 0. In other words, if indexOf returns -1 then 0 must be used.
+Pie Number of slices to send: Send
 

Rob Spoor wrote:Is it indexOf that gets evaluated to 0, or the result of that last line? Because the last line says that if indexOf returns anything larger than -1, 100 should be used and otherwise 0. In other words, if indexOf returns -1 then 0 must be used.



No it always returns 100 even when item.getSpocno() == "".

The only I could get it to work was to replace the item.spoc = "" with item.spoc = "N/A" in the item class property. This is the item class:

Squanch that. And squanch this tiny 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 531 times.
Similar Threads
indexOf and lastIndexOf question
some questions,please
Sun String IndexOf method API Question
Getting un-Expected Results From String IndexOf Method
looping into an array help
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 04:07:28.