Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Split A String Into Groups Of 4

DZone's Guide to

Split A String Into Groups Of 4

·
Free Resource

s = "ewerweouwroiuwe sdffd sdfds sfdsdf sdf"
s.scan(/.{1,4}/)
#=> ["ewer", "weou", "wroi", "uwe ", "sdff", "d sd", "fds ", "sfds", "df s", "df"]

# or 
s.scan(/./).each_slice(4).map(&:join)

Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}