Reputation: 45
I have a text field and button to search on XIB.
For example: i write "house of sun" on text field
How can i catch this sentence (house of sun) and transform into a variable and put "%20" on the spaces between the words ?
For the variable return for me (house%20of%20sun)
Upvotes: 0
Views: 157
Reputation: 6790
It's pretty straightforward:
var myString = "house of sun"
var myNewString = myString.stringByReplacingOccurrencesOfString(" ", withString: "%20", options: NSStringCompareOptions.LiteralSearch, range: nil)
Where var would be:
yourTextFieldName.text
Upvotes: 1