I have a string in the form "this is my title {{and this is what I have to replace}}"
.
The best way I found so far is:
let from = originalTitle.firstIndex(of: "{{") ?? 0
let to = originalTitle.firstIndex(of: "}}") ?? 0
if let textToReplace = originalTitle.slicing(from: from, to: to), !textToReplace.isEmpty {
return originalTitle.replacing(textToReplace, with: "XY")
}
return originalTitle
However I feel there has to be a better way to explicitly indicate two placeholders or markers and then replace whats inside. Any thoughts?
Thanks in advance!