my dog learned polymorphism*
The moose likes Beginning Java and the fly likes Splitting a String problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Splitting a String problem" Watch "Splitting a String problem" New topic
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: 443
    
    1


lastIndexOf() would be helpful.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37991
    
  22
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: 11155
    
  16

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.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
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: 19651
    
  18

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 - OCEEJBD 6
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: 19651
    
  18

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: 19651
    
  18

Completely unnecessary. lastIndexOf and indexOf return the same value if there's no match. You just have to check for that value.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Splitting a String problem
 
Similar Threads
doubt about String being cannt be changed !!!
Hi
classes in same folder, but not compiling
Jsp Expression tag inside <a href> html tag
string to float conversion round off problem