jyriand
jyriand

Reputation: 2524

Split long string into smaller pieces in Scala

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

Answers (2)

user2053898
user2053898

Reputation: 485

use String.substring and java.math.BigInteger

Upvotes: 0

om-nom-nom
om-nom-nom

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

Related Questions