I have a string containing many new line and spaces. I need to split it into fixed length sub strings. E.g
a = "This is some\nText\nThis is some text"
And now i would like to split it into say strings of length 17. so now it should result in
["This is some\nText", "\nThis is some tex", "t"]
Comment: My string may contain any character (white space/word etc)
"This is some\nText\nThis is some text".scan(/.{1,17}/m)
# => ["This is some\nText", "\nThis is some tex", "t"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With