我有一个包含许多新行和空格的字符串.我需要将其拆分为固定长度的子字符串.例如
a = "This is some\nText\nThis is some text"
Run Code Online (Sandbox Code Playgroud)
现在我想把它分成长度为17的字符串.所以现在它应该导致
["This is some\nText", "\nThis is some tex", "t"]
Run Code Online (Sandbox Code Playgroud)
评论:我的字符串可能包含任何字符(空格/单词等)
"This is some\nText\nThis is some text".scan(/.{1,17}/m)
# => ["This is some\nText", "\nThis is some tex", "t"]
Run Code Online (Sandbox Code Playgroud)