0

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.

0

1 Answer 1

10

Proper implementation is the exact same as Swift 3:

let str = "New York"
let replaced = str.replacingOccurrences(of: " ", with: "_")
Sign up to request clarification or add additional context in comments.

1 Comment

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.