BillPull
BillPull

Reputation: 7013

get parts of a URL in Flex from a string

I am trying to parse out pieces of a url string for comparison in Flex. I am really new to flex so just going to write what I want to do not sure if this code would be valid.

// urlone: http://www.helloworld.com/hello
// urltwo: http://www.goodbye.com/
public function compareURLHost(urlone:String,urltwo:String):Boolean
{
   var displayURL:URL = URL(urlone);
   var compareURL:URL = URL(urltwo);

   // compare www.helloworld.com to www.goodbye.com
   if(displauURL.hostname == compareURL.hostname)
      return true;

   return false;
}

Upvotes: 0

Views: 644

Answers (2)

Josh
Josh

Reputation: 8149

URLUtils can help, but they're not always what you need. For example, I had a project where I needed to remove a single directory from a url. It may sound dumb, but the client wanted their publicly viewable XML file to not show actual URLs and that was their solution. In that case, I did:

var url:String = "http://someurl.com/dir1/dir2/file.ext"
url = url.slice(url.indexOf('dir1'),5); //the four chars of the url + "/"
trace (url); //http://someurl.com/dir2/file.ext

You can also use String.replace to replace a set of characters with another set (say if my client had wanted to hide the url by swapping calling dir1 dir5 in the url)

var url:String = "http://someurl.com/dir5/dir2/file.ext"
var patten:RegExp = /dir5/;
url.replace(pattern,"dir1");
trace (url); //http://someurl.com/dir1/dir2/file.ext 

Upvotes: 0

badunk
badunk

Reputation: 4350

I think you're looking for URLUtils. You can get the port, hostname, serverName, etc.

Upvotes: 1

Related Questions