File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Head First Android this week in the Android forum!
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: 445
    
    1


lastIndexOf() would be helpful.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 43381
    
  32
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: 11815
    
  18

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: 20049
    
  30

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 - OCEJPAD 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: 20049
    
  30

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: 20049
    
  30

Completely unnecessary. lastIndexOf and indexOf return the same value if there's no match. You just have to check for that value.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Splitting a String problem
 
It's not a secret anymore!