• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question on string array values

 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have taken a string value in some test code and found all the "\n" values in the string via the split method and created a string array (notes) for each split value. However now I am needing to breakup each string[] (notes) value to a 45 char max length and create a new string for each 45 char length or less for each string[] value until I get to end of that string[] value.

Any suggestions or direction would be greatly appreciated.

Here is the code I am working with:

 
Srikanth Ramu
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take each element of the array and use length() and substring(int beginIndex, int endIndex) methods.

For more details:

http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html
 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I took a crack at the problem I explained above, but I am needing to break apart "noteLine" into 45 char chunk lines for each element in my string array and therefore the reason for this post.

Any help or direction would be greatly appreciated. Regards.

Here is the code I came up with but would appreciate any help:

 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following method should split each line into an array of String each 45 characters long (apart possibly from the last one).
I haven't tested it, so you may need to play around with the array indexes and substring parameters a little.
 
Guido Sautter
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you don't want to break up words, you might want to try this one:

 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys,

Thanks so much for your time and help. I will give this a try.

Again, thanks so much.

Regards.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic