• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

splitting String into substrings

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic