1

In the W3Schools they give this example:

var uri = "http://w3schools.com/my test.asp?name=ståle&car=saab";
var res = encodeURIComponent(uri);

Which does what I want however, when I run it I get an error that encodeURIComponent is not implemented.

try{    
    var str:String = "Contracts and Leases";
    var rtn = encodeURIComponent(str);
}catch(e){
    println(e)
}

added the above to a button i get the not implemented error. Is there an equivalent I just need to replace the spaces with %20s.

Bill F
  • 2,057
  • 3
  • 18
  • 39

1 Answers1

8

Use java.net.URLEncoder.encode(stringToEncode, "utf-8") so in your case do this:

try{    
    var str:String = "Contracts and Leases";
    var rtn = java.net.URLEncoder.encode(str, "utf-8");
}catch(e){
    println(e)
}
Per Henrik Lausten
  • 21,331
  • 3
  • 29
  • 76