简体   繁体   English

如何在AS3 Flash中替换反斜杠?

[英]How to replace backslash in AS3 Flash?

I'm trying to replace the backslashes of the url/path to get the file name of the swf: 我正在尝试替换url / path的反斜杠以获取swf的文件名:

var path:String = "C:\Test\myswf.swf"

var swfURL:String = path.replace(/\\/gi, "/");

var swfFileName:String = path.slice(path.lastIndexOf("/")+1, path.length).replace(".swf", "");

But it doesn't works. 但这是行不通的。 The response is: 'C:Testmyswf.swf'. 响应为:“ C:Testmyswf.swf”。 It's doesn't replace the string path. 它不会替换字符串路径。 How can i do it? 我该怎么做?

我认为您可能需要在URL字符串中转义反斜杠:

var path:String = "C:\\Test\\myswf.swf"

Try this regex: 试试这个正则表达式:

\\([^\\.]+)\.

Then get $1 然后得到$ 1

I've managed to solve this problem by "performing crazy" with the code below: 我设法通过以下代码“疯狂”解决了这个问题:

var reg:RegExp = new RegExp("\\d"+stage.loaderInfo.url, "gi");

var idswf:String = reg.toString().replace(/\\/g, "/");

idswf = idswf.split("/")[idswf.split("/").length-2].replace(".swf", "");

It may not be the best solution, but it worked well for me and can work for other people... 它可能不是最好的解决方案,但它对我来说效果很好,并且可以为其他人工作...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM