获取网址的文件名

时间:2011-06-15 09:12:24

标签: flex url flex3

在Flex 3中,我有一个类似

的字符串
var s:String = "http://www.abc.com/dump/one.htm#figure1"
//Want to parse this string and get the filename one.htm

我是flex的新手,尝试在谷歌搜索它,但没有得到任何解决方案。

2 个答案:

答案 0 :(得分:3)

var s:String = "http://www.abc.com/dump/one.htm#figure1"
var arr:Array=s.split("/");
var s2:String = arr[arr.length-1];
var s3 = s2.split("#")[0];
var s4 = s3.split("?")[0];
//s4 is the string you need.
//no matter what u try, this code will never break.

试试看,告诉我们。

答案 1 :(得分:1)

这对您有所帮助: http://flashascript.wordpress.com/2010/10/24/parsing-url-string-with-regular-expressions-regexp-in-actionscript-3/

var fileWithExtension:RegExp = /(?<=\/)(\w+)((\.\w+(?=\?))|(\.\w+)$)/g;
trace("file name with extension =", url.match(fileWithExtension));
// file name with extension = fileName.fileExtension

URI语法:http://en.wikipedia.org/wiki/URI_scheme#Generic_syntax