0

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)

Community
  • 1
  • 1
Mercenario
  • 45
  • 1
  • 6
  • textField.text to get the text and refer to http://stackoverflow.com/questions/24200888/any-way-to-replace-characters-on-swift-string for replacing characters – Kendel Jul 30 '15 at 21:29

1 Answers1

1

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
Fred Faust
  • 6,696
  • 4
  • 32
  • 55