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.
, :
NSString *myString = @"app://ga/ecommerce/product:playstation4"; NSArray* spliteArray = [myString componentsSeparatedByString: @"/"]; NSString* lastString = [spliteArray lastObject];
Swift 3 .
let fileName = "your/file/name/here" let fileArray = fileName?.components(separatedBy: "/") let finalFileName = fileArray?.last
: ""
:
NSURL *url = [NSURL URLWithString:@"app://ga/ecommerce/%7B%22product%22:%22playstation4%22..."]; NSString *last = [url lastPathComponent];
NSURL NSURL, lastPathComponent String. -, , URL-.
((\/){1}([a-z\-]*))$
1 , . , A-Z ( ..), "$" - ,
, , Regex mustStartLoadWithRequest, -. - - , . , - , - .
, '/' (json string), , lastComponent es/es.
, if-else, URL.
request.URL.absoluteString request.URL.host request.URL.fragment
, @Nitin Gohel .