|
|
| more useful options | |
| PerlMonks |
Answer: How can I split a string into chunks of size n bytes? |
| ( #296122=categorized answer: print w/ replies, xml ) | Need Help?? |
|
Q&A > strings > How can I split a string into chunks of size n bytes? contributed by davido
If by "bytes" you mean ASCII characters from a string, this is a simple and relatively fast solution:
This solution has a couple of nice bonuses. First, it will only return complete groups. If you have extra characters that don't complete out a group, it won't give them to you. Second, it is easily adaptable to any other data type that pack and unpack support. UPDATE: As Aristotle pointed out here, if you want the last group even if it's incomplete you may do this:
|
|
||||||||||||||||||||