Skip to content

Instantly share code, notes, and snippets.

@gkojax
Created April 10, 2013 08:30
Show Gist options
  • Save gkojax/5352837 to your computer and use it in GitHub Desktop.
Save gkojax/5352837 to your computer and use it in GitHub Desktop.
64文字の文字列を8文字ずつに区切ってリスト化する
//
// 64文字の文字列を8文字ずつに区切ってリスト化する
//
// 1234567890123456789012345678901234567890123456789012345678901234
// -> List(12345678, 90123456, 78901234, 56789012, 34567890, ....)
//
def aaa(s: String, l: Int): List[String] = {
def bbb(s: String, e: List[String]): Pair[String, List[String]] = s match {
case s if s.length < l =>
(s, e :+ s)
case s =>
val splited = s.splitAt(l)
bbb(splited._2, e :+ splited._1)
}
bbb(s, List())._2
}
val s = "1234567890123456789012345678901234567890123456789012345678901234"
aaa(s, 8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment