Search code examples
apache-flexflashactionscript-3flashvars

Action Script 3.0 : How to extract two value from string.?


HI

I have a URL

var str:String = "conn=rtmp://server.com/service/&fileId=myfile.flv"

or

var str:String = "fileId=myfile.flv&conn=rtmp://server.com/service/"

The str might be like this, But i need to get the value of "conn" and "fileId" from the string.

how can i write a function for that.


Solution

  • I'm guessing that you're having trouble with the second '=' in the string. Fortunatly, ActionScript's String.Split method supports splitting on strings, so the following code should work:

    var str:String = "conn=rtmp://server.com/service/&fileId=myfile.flv";
    var conn:String = (str + "&").Split("conn=")[1].Split("&")[0];
    

    and

    var str:String = "fileId=myfile.flv&conn=rtmp://server.com/service/";
    var fileId:String = (str + "&").Split("fileId=")[1].Split("&")[0];
    

    Note: I'm appending a & to the string, in case the string didn't contain any url parameters beyond the one we're looking for.