• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Splitting a String problem

 
vivek kumar jaiswal
Greenhorn
Posts: 24
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 445
1
Java Spring
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

lastIndexOf() would be helpful.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50289
80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12203
35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 144
Fedora Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the JavaDoc for the String class

Do you see any methods listed there that might solve your problem?
 
vivek kumar jaiswal
Greenhorn
Posts: 24
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Finally I solve this problem.


with regards,
VIVEK
 
Rob Spoor
Sheriff
Pie
Posts: 20671
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20671
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20671
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Completely unnecessary. lastIndexOf and indexOf return the same value if there's no match. You just have to check for that value.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic