Replace a character on String swift
Solution:
The below function is used to replace the particular character with another character.
If you want to replace in a particular range then use the range function to replace the characters.
Code:
let str = "This is my string"
let newString = str.replacingOccurrences(of: " ", with: "+", options: .literal, range: nil)
The below function is used to replace the particular character with another character.
If you want to replace in a particular range then use the range function to replace the characters.
Code:
let str = "This is my string"
let newString = str.replacingOccurrences(of: " ", with: "+", options: .literal, range: nil)
Comments
Post a Comment