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
extension String { | |
/// Truncates the string to length number of characters and | |
/// appends optional trailing string if longer | |
func truncate(length: Int, trailing: String? = nil) -> String { | |
if self.characters.count > length { | |
return self.substringToIndex(self.startIndex.advancedBy(length)) + (trailing ?? "") | |
} else { | |
return self | |
} | |
} |
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
extension String { | |
/// Truncates the string to length number of characters and | |
/// appends optional trailing string if longer | |
func truncate(length: Int, trailing: String? = nil) -> String { | |
if self.characters.count > length { | |
return self.substringToIndex(self.startIndex.advancedBy(length)) + (trailing ?? "") | |
} else { | |
return self | |
} | |
} |