Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete last path component of a String in Swift?

Tags:

I have a String 11/Passion/01PassionAwakening.mp3 and I need to delete the last path component 01PassionAwakening.mp3 in order to get 11/Passion.

How can I do this while saving both components?

like image 533
SUDHAKAR RAYAPUDI Avatar asked Nov 23 '15 10:11

SUDHAKAR RAYAPUDI


1 Answers

You can separate your url into two parts like so:

let str : NSString = "www.music.com/Passion/PassionAwakening.mp3"  let path : NSString = str.stringByDeletingLastPathComponent let ext : NSString = str.lastPathComponent  print(path) print(ext) 

Output

www.music.com/Passion PassionAwakening.mp3 

For more info please have a look at this link.

like image 64
Dharmbir Singh Avatar answered Sep 28 '22 02:09

Dharmbir Singh