vivek kumar jaiswal
,
Greenhorn
Jun 06, 2011 04:09:28
Hi Ranchers,
Please solve this problem.
How to split this String to two parts like
Part 1:- hello.hello1.hello2
Part 2:- jpg
please solve this problem
regards,
VIVEK
Rajkamal Pillai
,
Ranch Hand
Jun 06, 2011 04:20:31
lastIndexOf() would be helpful.
Campbell Ritchie
,
Marshal
staff
Jun 06, 2011 07:50:03
Please tell us what you have got so far. We don't simply give out answers to that sort of question.
fred rosenberger
,
lowercase baba
staff
Jun 06, 2011 08:50:32
I would say the problem is not well-defined. For example, what if the string was "hello.hello1.hello2.jpg.hello3"? What if it was "hello.hello1.hello2"? What if it were "JPG"?
Simply providing one example does NOT define the problem.
Mike Zal
,
Ranch Hand
Jun 06, 2011 11:06:44
Here is the JavaDoc for the String class
Do you see any methods listed there that might solve your problem?
vivek kumar jaiswal
,
Greenhorn
Jun 06, 2011 21:48:26
Hi all,
Finally I solve this problem.
with regards,
VIVEK
Rob Spoor
,
Sheriff
staff
Jun 07, 2011 01:41:13
I quote one case:
fred rosenberger wrote: What if it were "JPG"?
More precisely, what will x be in that case, and what will be the results?
Prasanna Kumaar
,
Ranch Hand
Jun 07, 2011 05:00:09
Rob Spoor wrote: I quote one case:
fred rosenberger wrote: What if it were "JPG"?
More precisely, what will x be in that case, and what will be the results?
i wont think it will cause any effect as you are using only lastIndexOf
Rob Spoor
,
Sheriff
staff
Jun 07, 2011 05:06:24
And what does lastIndexOf return if there is not dot in the String? And what will that specific return value do with the calls to substring?
Prasanna Kumaar
,
Ranch Hand
Jun 30, 2011 03:07:45
Rob Spoor wrote: And what does lastIndexOf return if there is not dot in the String? And what will that specific return value do with the calls to substring?
First check for indexOf(".") if it returns true then check for LastIndexOf(".")
Rob Spoor
,
Sheriff
staff
Jun 30, 2011 04:03:30
Completely unnecessary. lastIndexOf and indexOf return the same value if there's no match. You just have to check for that value.
Nothing up my sleeve ... and ... presto! A tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com