Created
April 10, 2013 08:30
64文字の文字列を8文字ずつに区切ってリスト化する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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