Last active
January 6, 2018 07:43
-
-
Save d-date/dc6bb413465063b96e6d96d7ea303d56 to your computer and use it in GitHub Desktop.
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
extension String { | |
func split(_ size: Int) -> [String] { | |
return stride(from: 0, to: self.count, by: size).map { i -> String in | |
let startIndex = self.index(self.startIndex, offsetBy: i) | |
let endIndex = self.index(startIndex, offsetBy: size, limitedBy: self.endIndex) ?? self.endIndex | |
return String(self[startIndex..<endIndex]) | |
} | |
} | |
} | |
print("あけましておめでとうございます。今年もどうぞよろしくお願いします。".split(5)) | |
//["あけまして", "おめでとう", "ございます", "。今年もど", "うぞよろし", "くお願いし", "ます。"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment