从网址字符串中获取最后一个'/'(斜杠)之后的所有字符 [英] Get all characters after the last '/' (slash) from url string
本文介绍了从网址字符串中获取最后一个'/'(斜杠)之后的所有字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从网址字符串中获取最后一个'/'(斜杠)之后的所有字符?
How to get all characters after the last '/' (slash) from url string?
在对某些站点进行Webview请求时,我从URL方案中收到了json字符串.例如:
I receive a json string from my URL scheme when making webview request for certain site. For example:
app://ga/ecommerce/%7B%22product%22:%22playstation4%22 ...}]
app://ga/ecommerce/%7B%22product%22:%22playstation4%22...}]
我想在最后'/'(斜杠)之后获取子字符串.
I would like to grab the substring after the last '/'(slash).
如何实现?我可以知道正则表达式的格式是什么吗?
How can I achieve it? May I know what is the format of Regex?
避免使用
NSRange lastDotRange = [sURL rangeOfString:@"/" options:NSBackwardsSearch];
因为我可能在json中转义了"/" .
because I might have escaped '/' in my json.
谢谢.
推荐答案
对于Swift 3,请尝试以下操作.
For Swift 3 try this.
let fileName = "your/file/name/here"
let fileArray = fileName?.components(separatedBy: "/")
let finalFileName = fileArray?.last
输出:此处"
这篇关于从网址字符串中获取最后一个'/'(斜杠)之后的所有字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文