Skip to content

Instantly share code, notes, and snippets.

@mugishap
Created March 5, 2023 07:55
Show Gist options
  • Save mugishap/0ba5ba7bcd9b22f7504d38c05b8cb7e7 to your computer and use it in GitHub Desktop.
Save mugishap/0ba5ba7bcd9b22f7504d38c05b8cb7e7 to your computer and use it in GitHub Desktop.
extension String {
func removeChar(character: String) -> String {
if(character.count > 1) {
print("Only one character can be removed at a time")
return "Error occured"
}
var newStr: String = ""
for current in self {
if(character == "\(current)"){
continue
}
newStr += "\(current)"
}
return newStr
}
}
var word = "advantage"
print(word.removeChar(character: "n"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment