用单斜杠替换双反斜杠

时间:2013-05-18 20:58:56

标签: actionscript-3 flex actionscript flex4

如何用单斜杠替换doublebackslash?无法在任何地方找到一个例子。 即

“c:\\ this \\ is \\ a \\ folder \\ myfile.jpg”to“c:\ this \ is \ a \ folder \ myfile.jpg”

1 个答案:

答案 0 :(得分:0)

您可以使用String.replace()功能执行此操作:

var rx:RegExp = /\\\\/g;
var s:String = "c:\\\\folder\\\\folder\\\\folder\\\\file.ext";

trace ( s );
s = s.replace ( rx, "\\" );
trace ( s );

你需要转义文字字符串中的\字符,这就是为什么它在上面的代码中翻了一倍。