Last active
August 29, 2015 14:18
-
-
Save akramhussein/f008d9e572ca8d3312e6 to your computer and use it in GitHub Desktop.
String+RemoveWords Extension
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 removeWords(words: [String]) -> String | |
{ | |
var cleanedString = self | |
// Remove common words | |
for word in words | |
{ | |
cleanedString = cleanedString.stringByReplacingOccurrencesOfString(word, withString: "", options: NSStringCompareOptions.LiteralSearch, range: nil) | |
} | |
// strip newlines and spaces | |
cleanedString = cleanedString.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet()) | |
return cleanedString | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment