How to remove "http: //" from string in actionscript?
This may sound basic, but I don't know how to do it - anyone else?
I have a line that looks like this:
private var url:String = "http://subdomain";
What I need so that I can do this:
url.replace(regex,"");
and complete it?
trace(url); // subdomain
Or is there an even better way to do this?
0
a source to share
3 answers
ActionScript does support much richer regex reuse than completed by bewdwyr. You just need to use the actual Regexp, not the string, as the replacement parameter. :-)
var url:String;
url = "https://foo.bar.bz/asd/asdasd?asdasd.fd";
url = url.replace(/^https?:\/\//, "");
To make it perhaps even clearer
var url:String;
var pattern:RegExp = /^https?:\/\//;
url = "https://foo.bar.bz/asd/asdasd?asdasd.fd";
url = url.replace(pattern, "");
RegExp is a first class ActionScript type.
Note that you can also use $ char to end the string and use () to capture substrings for later reuse. There is a lot of power here!
+1
a source to share