How can I replace the characters in string in progression in swift?

2383 views swift

I'm a beginner in Swift. And now I work on my project and I've got stuck on the following problem. e.g. I have a text:

Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda.

(Honestly I don't know what text will be. It will be download on app by users). I would like for example to replace all spaces on "+" in progression. At 1/3 of text every third space must be replaced. At 2/3 of text every second space must be replaced. And finally at third part of text every space must be replaced on "+". Text can be divided on more than 3 parts but now it doesn't matter. The problem is in algorithm of selective replacement in arithmetic progression. If it's not difficult please give me a hint. Thank you.

answered question

1 Answer


make your text into three parts then use :

clearTextFiled.text?.replacingOccurrences(of: ",", with: "")

posted this

Have an answer?


Please login first before posting an answer.