Join 500+ Software Testing professionals. Solve problem and get your problem solved. Register Now!

How do I separate string using space and dot

Solved 2 Answers 41 Views Programming
0 2
Using above code I could retrive the String. Now I need to split it using space and then dot.
related to an answer for: read text file using Java

2 Answers

Best answer
You can use below code to split your String.


String[] splittedString = myString.split(","); // if (,) comma is your delimiter
answered by (151 points)
selected by
Try below line of code.

str = "1.Apple 2.Orange 3.Grape";
String[] splited = str.split("\\s+"); //This will cause any number of consecutive spaces to split your string into tokens.
for(int i=0;i<str.length;i++){
String[] newSplitted = splited[i].split(".");
System.out.println("Splited values:"+newSplitted[0] + " && " + newSplitted[1]);

Hope it helps
answered by (327 points)
reshown by

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.