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

时间:2018-01-30 04:31:46

标签: string actionscript-3 url

我从网站获取这些网址的路径始终相同,只是文件名正在变化。

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

我的AS3代码,每天都在这个网站上抓住网址(天气)。

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

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

类似的东西:

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;

但是如何判断“用名称文件结束?”

谢谢

1 个答案:

答案 0 :(得分:1)

为什么不定义自己的网址?

这样的事情应该这样做:

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;