views:

85

answers:

4

I am working on a flex site,

I want to parse the string below: http://virtual.s1.c7beta.com/rpc/raw?c=Pictures&m=download%5Fpicture&key=a4fb33241662c35fe0b46c7e40a5b416&session%5Fid=2b7075f175f599b9390dd06f7b724ee7

and remove the &session_id=2b7075f175f599b9390dd06f7b724ee7 from it.

How should i do it.

also later on when i get the url from database without session_id, i will attach the new session_id to it. Please tell me how to do that too.

Regards Zeeshan

+1  A: 

If you're not sure that sessionid will be last you could split on the & using the as3 string.split functionhttp://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/String.html#split%28%29

then rebuild the string using a for loop leaving out strings that start with session_id using the string.indexOf function http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/String.html#indexOf%28%29 to see if "session_id" is at index 0

John Boker
A: 

You can use regular expressions in Flex ... here's an example.

Chris Nicol
A: 

Assuming the session ID will always be the last variable in the query string:

var newStr:String = myStr.slice(0, myStr.indexOf("&session"));
Tegeril
+3  A: 

Not the short version but you can use URLVariable to get all the field(name, value) into an object and then add or delete any field you want.

Separate url and query:

var url : String = "http://virtual.s1.c7beta.com/rpc/raw?c=Pictures&m=download%5Fpicture&key=a4fb33241662c35fe0b46c7e40a5b416&session%5Fid=2b7075f175f599b9390dd06f7b724ee7";
var idxQMark : int = url.indexOf("?");
var qry : String = "";

Build url variable from query

var uv : URLVariables = new URLVariables();
if (idxQMark > 0) {
 qry = url.substr(idxQMark + 1);
 url = url.substr(0, idxQMark);
 uv.decode(qry);
}

NOw you can access whatever field you need or delete them

delete uv.session_id;

Rebuild the query when needed

qry = uv.toString();

// get back you new URL

if (qry != "") {
 url = url + "?" + qry;
}
Patrick
Nice and robust.
Tegeril
@Tegeril Thank you :)
Patrick