• 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

Question on string array values

 
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic