Posted By

Activetuts on 01/13/11


Tagged


Versions (?)

Who likes this?

13 people have marked this snippet as a favorite

chus
elbjoern
ichnoweb
kure69
albertomori
AndrewPotter
JaaQ
elderhsouza
benediktvaldez
merritt212
jbyerson
coutlasssupreme
flashdeveloper


Strip http:// or https:// From a String, Optionally Removing www.


 / Published in: ActionScript 3
 

URL: http://enva.to/e4ig6z

This function takes a string and returns a copy with all occurrences of http:// and https:// removed. The string, "Please visit http://example.com to find out more" would convert to "Please visit example.com 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 example.com and www.example.com 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.