Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Split String Based On String Length

 
San Smith
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

I am trying to split a string based on length(example length 5) of the string. But I am having a issues with this substring(start, end) method. I get all substring which are of length 5. But if the last substring is less than 5 then I am not getting that last substring. But I need the last substring even if it is less than 5. I am wondering if some one can help me. Let me know if anything is not clear.

Thank you for your help.



>
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the problem you are walking into with the last iteration is that you are running into a StringIndexOutOfBoundsException ...

This should work ..





I did not test this but it should work.
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Almost right ..

this


needs to be

 
San Smith
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sebastian,

Thank you so much. It worked.

Thank you again
 
Mahesh Gurrapu
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the solution Splitting String for given length
 
Campbell Ritchie
Sheriff
Pie
Posts: 50277
80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

They may not need the solution after 4½ years.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic