Get all characters after last "/" (slash) from url string

How to get all characters after the last "/" (slash) from url string?

I get a json string from my URL scheme when I execute a web view request for a specific site. For instance:

Application: // ha / e-commerce /% 7B% 22product% 22:% 22playstation4% 22 ...}]

I would like to grab a substring after last '/' (slash).

How can i achieve this? Can I find out what the Regex format is?

Avoid using

NSRange lastDotRange = [sURL rangeOfString:@"/" options:NSBackwardsSearch];

because in my json I could escape '/' .

Thank.

+6
6

, :

NSString *myString = @"app://ga/ecommerce/product:playstation4"; 
NSArray* spliteArray = [myString componentsSeparatedByString: @"/"];
NSString* lastString = [spliteArray lastObject];
+2

Swift 3 .

let fileName = "your/file/name/here"
let fileArray = fileName?.components(separatedBy: "/")
let finalFileName = fileArray?.last

: ""

+10

:

    NSURL *url = [NSURL URLWithString:@"app://ga/ecommerce/%7B%22product%22:%22playstation4%22..."];
    NSString *last = [url lastPathComponent];
+2

NSURL NSURL, lastPathComponent String. -, , URL-.

+1

:

((\/){1}([a-z\-]*))$

1 , . , A-Z ( ..), "$" - ,

0

, , Regex mustStartLoadWithRequest, -. - - , . , - , - .

, '/' (json string), , lastComponent es/es.

, if-else, URL.

request.URL.absoluteString
request.URL.host
request.URL.fragment

, @Nitin Gohel .

0

All Articles