To remove a specific character from a string in Swift, you can use the `replacingOccurrences` method.
In this example,
str
with a value of "Hello World"
.replacingOccurrences
method to replace all occurrences of 'l' with an empty string in str
.replacingOccurrences
method returns a new string with the specified characters replaced.str
.import Foundation
let str = "Hello World"
let modifiedStr = str.replacingOccurrences(of: "l", with: "")
print("Modified string:", modifiedStr)
Modified string: Heo Word
In this example,
str
with a value of "apple"
.replacingOccurrences
method to replace all occurrences of 'a' with an empty string in str
.replacingOccurrences
method returns a new string with the specified characters replaced.str
.import Foundation
let str = "apple"
let modifiedStr = str.replacingOccurrences(of: "a", with: "")
print("Modified string:", modifiedStr)
Modified string: pple
In this tutorial, we learned How to Remove specific Character from a String in Swift language with well detailed examples.