Forums Register Login

Splitting a String problem

+Pie Number of slices to send: Send
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
2
+Pie Number of slices to send: Send

lastIndexOf() would be helpful.
+Pie Number of slices to send: Send
Please tell us what you have got so far. We don't simply give out answers to that sort of question.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Here is the JavaDoc for the String class

Do you see any methods listed there that might solve your problem?
+Pie Number of slices to send: Send
Hi all,

Finally I solve this problem.


with regards,
VIVEK
+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
 

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
+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
 

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(".")
+Pie Number of slices to send: Send
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


reply
reply
This thread has been viewed 1193 times.
Similar Threads
classes in same folder, but not compiling
string to float conversion round off problem
Jsp Expression tag inside <a href> html tag
Hi
doubt about String being cannt be changed !!!
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 15:12:29.