Question: I have this url <https://storage.googleapis.com/user_avatars/63/img_-qLgH80SBqNhMRYbDQeccg.jpg> 
I need only qLgH80SBqNhMRYbDQeccg image name from this link In ui Image

Answer: 
You can use NSURL to safely isolate the filename then use substring to get the part you want.

```
let s = "https://storage.googleapis.com/user_avatars/63/img_-qLgH80SBqNhMRYbDQeccg.jpg"

```

**Swift 2**

```
if let url = NSURL(string: s),
    withoutExt = url.URLByDeletingPathExtension,
    name = withoutExt.lastPathComponent {
    let result = name.substringFromIndex(name.startIndex.advancedBy(5))
    print(result)
}

```

**Swift 3**

```
if let url = URL(string: s),
    withoutExt = try? url.deletingPathExtension(),
    name = withoutExt.lastPathComponent {
    let result = name.substring(from: name.index(name.startIndex, offsetBy: 5))
    print(result)
}

```

**Swift 4**

```
if let url = URL(string: s) {
    let withoutExt = url.deletingPathExtension()
    let name = withoutExt.lastPathComponent
    let result = name.substring(from: name.index(name.startIndex, offsetBy: 5))
    print(result)
}

```

---

Prints:

> 
> qLgH80SBqNhMRYbDQeccg
> 
> 
>
What about something that uses `NSURLComponents` to break up the URL:

```
func parseURLForFileName(url:String) ->String?
{
    let components = NSURLComponents(string: url)
    if let path:NSString = components?.path
    {
        let filename = path.lastPathComponent
        if let range = filename.rangeOfString("_-")
        {
            return filename.substringFromIndex(range.endIndex)
        }
    }
    return nil
}

```

You would then call it like this:

```
    let name = parseURLForFileName("https://storage.googleapis.com/user_avatars/63/img_-qLgH80SBqNhMRYbDQeccg.jpg")
    print(name)

```