Skip to content

Instantly share code, notes, and snippets.

@sgr-ksmt
Created March 22, 2016 03:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sgr-ksmt/7a282af2bc8ecf548948 to your computer and use it in GitHub Desktop.
Save sgr-ksmt/7a282af2bc8ecf548948 to your computer and use it in GitHub Desktop.
String#split
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