aspose file tools
The moose likes Beginning Java and the fly likes splitting String into substrings Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "splitting String into substrings" Watch "splitting String into substrings" New topic
Author

splitting String into substrings

ramakrishna ranga
Greenhorn

Joined: Sep 22, 2007
Posts: 3
String s = "6158"; i have to split this as substrings like 6, 1, 5, 8, 61, 15, 58, 615, 158, and 6158. Here is my code

code:
--------------------------------------------------------------------------------


String s = "6158";
for(int i=0;i<s.length();i++)
{
System.out.println(s.charAt(i));
}
int i=0;
int l=1;
while(i<s.length()){
while(l<=s.length()){
System.out.println(s.substring(i,l));
l++;
}
i++;
}

--------------------------------------------------------------------------------

Output: 2 3 1 9 2 23 231 2319 But i am not able to get the all the values, i have tried lot of ways. please any one help me how to get it.
Freddy Wong
Ranch Hand

Joined: Sep 11, 2006
Posts: 959



SCJP 5.0, SCWCD 1.4, SCBCD 1.3, SCDJWS 1.4
My Blog
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: splitting String into substrings
 
Similar Threads
Few Tricky Ques.
When does a NullPointerException occurs?
SCJP6 study - regex string.split - strange results, can anyone explain please?
String to String array
There is no main method in class: Times - How do I resolve it?