-3

What is the best way to split this String into two using Swift?

"https://apod.nasa.gov/apod/http://nusoft.fnal.gov/nova/public/img/FD-evt-echo.gif" 

I only need the second part of url in the String. In this example, in this case I just need:

"http://nusoft.fnal.gov/nova/public/img/FD-evt-echo.gif" 
2
  • Possible duplicate of How to Split String Using Regex Expressions Commented Aug 13, 2018 at 1:50
  • Hi Samuel, you should write logic to fix this error which is from Nasa APOD API. This is already opened in their Github repo Check and keep follow the issue so you will get to know when there'll be an update. Commented Oct 4, 2018 at 6:22

1 Answer 1

1
let str = "https://apod.nasa.gov/apod/http://nusoft.fnal.gov/nova/public/img/FD-evt-echo.gif" if let lastStr = str.components(separatedBy: "http").last { let result = "http" + lastStr print(result) } 

Console Output: http://nusoft.fnal.gov/nova/public/img/FD-evt-echo.gif

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.