Skip to content

Instantly share code, notes, and snippets.

@hashaam
Last active March 22, 2019 10:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hashaam/4332966d6a2333ac3c358c44f5cf1a90 to your computer and use it in GitHub Desktop.
Save hashaam/4332966d6a2333ac3c358c44f5cf1a90 to your computer and use it in GitHub Desktop.
Get filename without extension
// https://hashaam.com/2017/09/02/get-filename-without-extension
let path = "hls_a128_v4.m3u8"
let url = URL(string: path)
let filename = url?.deletingPathExtension().lastPathComponent
print(filename) // hls_a128_v4
let fileExtension = url?.pathExtension
print(fileExtension) // m3u8
@rhcpfan
Copy link

rhcpfan commented Mar 22, 2019

This fails if the filename contains spaces

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment