Created
October 18, 2018 23:44
-
-
Save Zhong-z/4b1661fc5cf4dcb4b8d7fe07eb7f7071 to your computer and use it in GitHub Desktop.
Split a string into chunks of specified size without breaking words
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
line = 'something very long that we need to split it ----llll aaa ' | |
# the size/limit is 30 | |
line.scan(/.{1,30}\b|.{1,30}/).map(&:strip) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment