-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"
  • Possible duplicate of [How to Split String Using Regex Expressions](https://stackoverflow.com/questions/42476395/how-to-split-string-using-regex-expressions) – ekscrypto Aug 13 '18 at 01: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](https://github.com/nasa/apod-api/issues/6) Check and keep follow the issue so you will get to know when there'll be an update. – Hemang Oct 04 '18 at 06:22

1 Answers1

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

udbhateja
  • 948
  • 6
  • 21