Skip to content

Instantly share code, notes, and snippets.

@boraseoksoon
Last active August 8, 2018 10:06
Show Gist options
  • Select an option

  • Save boraseoksoon/788dfe7bfc75c9b01eb830317873cd51 to your computer and use it in GitHub Desktop.

Select an option

Save boraseoksoon/788dfe7bfc75c9b01eb830317873cd51 to your computer and use it in GitHub Desktop.
remove all match list strings to need to be removed in a given string
extension String {
func remove(stringList: [String]) -> String {
return stringList.reduce(self) {
return $0.replacingOccurrences(of: $1, with: "")
}
}
}
let testEmStr = "<em>#<\\/em>swift"
let trimStr = testEmStr.remove(stringList:["<em>", "<\\/em>"])
testEmStr // "<em>#<\\/em>swift"
trimStr // "#swift"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment