Created
March 5, 2023 07:55
-
-
Save mugishap/0ba5ba7bcd9b22f7504d38c05b8cb7e7 to your computer and use it in GitHub Desktop.
This file contains 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 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