Last active
September 27, 2017 16:22
-
-
Save aorcsik/c8210a84f163b1b644c0 to your computer and use it in GitHub Desktop.
Revisions
-
aorcsik revised this gist
Nov 7, 2014 . 1 changed file with 4 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -8,4 +8,7 @@ extension String { return self } } } // Example let str = "This is a long string".truncate(10, trailing: "...") // "This is a ..." -
aorcsik created this gist
Nov 7, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ 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 countElements(self) > length { return self.substringToIndex(advance(self.startIndex, length)) + (trailing ?? "") } else { return self } } }