| Author |
Splitting a String problem
|
vivek kumar jaiswal
Greenhorn
Joined: Jul 31, 2008
Posts: 24
|
|
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
Joined: Mar 02, 2005
Posts: 435
|
|
lastIndexOf() would be helpful.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32712
|
|
|
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
Bartender
Joined: Oct 02, 2003
Posts: 9955
|
|
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.
|
Never ascribe to malice that which can be adequately explained by stupidity.
|
 |
Mike Zal
Ranch Hand
Joined: May 04, 2011
Posts: 144
|
|
Here is the JavaDoc for the String class
Do you see any methods listed there that might solve your problem?
|
OCJP6, OCWCD5
|
 |
vivek kumar jaiswal
Greenhorn
Joined: Jul 31, 2008
Posts: 24
|
|
Hi all,
Finally I solve this problem.
with regards,
VIVEK
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
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?
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Prasanna Kumaar
Ranch Hand
Joined: Feb 08, 2011
Posts: 30
|
|
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
Joined: Oct 27, 2005
Posts: 19216
|
|
|
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
Joined: Feb 08, 2011
Posts: 30
|
|
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
Joined: Oct 27, 2005
Posts: 19216
|
|
|
Completely unnecessary. lastIndexOf and indexOf return the same value if there's no match. You just have to check for that value.
|
 |
 |
|
|
subject: Splitting a String problem
|
|
|