Created
March 22, 2016 03:36
-
-
Save sgr-ksmt/7a282af2bc8ecf548948 to your computer and use it in GitHub Desktop.
String#split
This file contains 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
public extension String { | |
public func split(length: Int) -> [String] { | |
let array = self.characters.map { String($0) } | |
let limit = self.characters.count | |
return 0 | |
.stride(to: limit, by: length) | |
.map({ | |
array[$0..<$0.advancedBy(length, limit: limit)].joinWithSeparator("") | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment