Avatar ·

How to replace characters in a String in Swift? (replace characters in String)

Hi everyone! I just started learning Swift and ran into a problem working with strings. I need to replace certain characters in a string. For example, I have a string "Hello World" and I want to replace all spaces with hyphens to get "Hello-World". Or replace all letters 'o' with '0'. In other languages like Python or JavaScript, I just used the replace() method, but in Swift I can't find anything similar. I tried writing something like: ```swift var text = "Hello World" text.replace(" ", "-") // Error! ``` But it doesn't work. The compiler complains and says there is no such method. I also read that in Swift, strings are not just arrays of characters, but complex structures due to Unicode support. Maybe that's why the standard replacement methods work differently? Can anyone advise?