Chop a string in Ruby into fixed length string ignoring (not considering/regardless) new line or space characters

前端 未结 5 1020
别那么骄傲
别那么骄傲 2021-01-02 21:19

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\"
<         


        
5条回答
  •  抹茶落季
    2021-01-02 21:45

    "This is some\nText\nThis is some text".scan(/.{1,17}/m)
    # => ["This is some\nText", "\nThis is some tex", "t"]
    

提交回复
热议问题