Alright, so I am pulling weather data into my app, and in order to pull the location based api url, I have to insert the city and the shorthand state (i.e. CA, MO, NY, ... etc.) into the api url. I am able to get both the city and shorthand state, the problem is any spaces in the city need to be formatted as underscores, such as that New York has to equal New_York. How do I go about doing this? The city name is in a String format. I already see answers on Stack Overflow, but none are Swift 4.
Asked
Active
Viewed 6,816 times
1 Answers
9
Proper implementation is the exact same as Swift 3:
let str = "New York"
let replaced = str.replacingOccurrences(of: " ", with: "_")

user3483203
- 50,081
- 9
- 65
- 94
-
The question is most likely a duplicate as noted above, it's usually best to just point to a question that has an answer than to answer it again. – Jan 10 '18 at 02:46