Posted By

tuffstudio on 01/19/11


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite


Remove "http://" &/or "www"

 / Published in: ActionScript 3

This function takes a string and returns a copy with all occurrences of http:// and https:// removed. The string, "Please visit to find out more" would convert to "Please visit to find out more". Generally this is more compact as the http:// is redundant when you are obviously referring to a URL.

Optionally, this function can also strip the www subdomain by passing true as the second parameter. It's set to false by default as and could theoretically contain different websites.

  1. function stripHttp(string:String, stripWWW:Boolean = false):String
  2. {
  3. var s:String = string;
  4. var regexp:RegExp = new RegExp(!stripWWW ? "https*:\/\/" : "https*:\/\/(www\.)*", "ig");
  5. return s.replace(regexp, "");
  6. }

Report this snippet  

You need to login to post a comment.