Reputation: 2524
I'm trying to solve Project Euler's problem with scala Large sum problem, but failing to find a way how can I split one big string into hundred 50 character long pieces. Of course I could use some kind of foreach loop and do it old imperative style, but there has to be a functional way also. Ideally the result would be a list of 100 strings.
Upvotes: 2
Views: 938
Reputation: 62855
val chunkLen = 3
"abcdefg".grouped(chunkLen).toList
// List(abc, def, g)
Of course, toList isn't necessary if you want iterative processing
Upvotes: 3