替换 url 但保留文件名 (AS3)

Replace url but keep the files names (AS3)

我从网站上获取了这些 url,它们的路径始终相同,只是文件名发生了变化。

"http://www.swellmap.co.nz/style/img/weathericons/rain.png"

我的 AS3 代码,每天(天气)都在这个网站上捕获 url。

我想用我的替换每个图标。

有没有办法替换路径但保留文件名?所以我只需要上传一个同名文件:

类似于:

Url = "http://www.swellmap.co.nz/style/img/weathericons/rain.png";
myUrl = "http://www.mywebsite.nc/weather/";
Url.replace("http://www.swellmap.co.nz/style/img/weathericons/",myUrl); 
url_Icon= myUrl;

但是如何判断“以文件名结尾?

谢谢

您为什么不定义自己的 URL?

应该这样做:

var myNewURL:String = Url.replace("http://www.swellmap.co.nz/style/img/weathericons/", myUrl); 

如果图片名称前的部分不一样:

// split the string by "/", this will result in ["http:", "", "www.swellmap.co.nz", "style", "img", "weathericons", "rain.png"]
// your imagename will be on the last position of the array
var urlSplit:Array = Url.split("/");

// get the image name from the last position of the array
var imageName:String = urlSplit[(urlSplit.length - 1)];

var newUrl:String = myUrl + imageName;