Swift 3 Trimming of special characters
extension String { | |
func trim(_ string: String) -> String { | |
var set = Set<Character>() | |
for c in string.characters { | |
set.insert(Character(String(c))) | |
} | |
return trim(set) | |
} | |
func trim(_ characters: Set<Character>) -> String { | |
if let index = self.characters.index(where: {!characters.contains($0)}) { | |
return self[index..<self.endIndex] | |
} else { | |
return "" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment