This week's book giveaway is in the Server-Side JavaScript and NodeJS forum.
We're giving away four copies of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques and have Mario Casciaro & Luciano Mammino on-line!
See this thread for details.
Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

String bytes manipulation

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello there,

Someone could help me doing the following operation:

I have a String(a big one), and I need to "split" this String in smaller Strings of 50 bytes each, and put all these 50 bytes Strings into an ArrayList.

Thank you guys!!
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We love to help folks here, but we also ask that you Do Your Own Work. What have you tried to solve your problem? Do you have some code we can discuss?
 
Gustavo Berndorfer Goldhardt
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm new in Java, and I have just a little experience in String manipulation. This is a quick problem to solve if you are a Java expert or at least have a considerable experience in it, but if you are a newbie(like me) this is an extremelly hard operation. I not asking you to solve the problem for me, but if you can point me a solution, or even indicate examples in manipulating bytes of a String. But if you have the algoritihm, I would be very happy if you share it with me and the other newbies in this community...

Thank you very much!

 
Gustavo Berndorfer Goldhardt
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And yes, I tryed to solve the problem myself... But I'm getting lost and confused when I need to manipulate bytes instead of characters.
 
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let me see if I understand this, in the ArrayList you will store Strings of around 50 bytes, correct?

You must know that in Java, String may contain characters in different encodings (i.e ASCII, UTF-8, UTF-16, etc, etc, etc).

Therefore, the binary representation of the String characters could vary depending on the enconding. If your encoding is ASCII then in binary form most probably every byte would correspond to a character, but the same cannot be said of all other encodings. Also, it is important to highligh that the number of bytes required to store the characters of a String in particular enconding has nothing to do with the size in bytes of a String object if serialized.

That being said, in what encoding should your strings fit in 50 bytes chunks?

I ask this because spliting the string based on bytes might leave you with a chuck of bytes that has not sense in particular encoding.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic