wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Split String Based On String Length Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Split String Based On String Length " Watch "Split String Based On String Length " New topic
Author

Split String Based On String Length

San Smith
Greenhorn

Joined: Feb 10, 2008
Posts: 14
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

Joined: Feb 23, 2009
Posts: 1183
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.

JDBCSupport - An easy to use, light-weight JDBC framework -
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
Almost right ..

this


needs to be

San Smith
Greenhorn

Joined: Feb 10, 2008
Posts: 14
Hi Sebastian,

Thank you so much. It worked.

Thank you again
Mahesh Gurrapu
Greenhorn

Joined: Aug 26, 2014
Posts: 1
Here is the solution Splitting String for given length
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39834
    
  28
Welcome to the Ranch

They may not need the solution after 4½ years.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Split String Based On String Length