posts - 30,  comments - 50,  trackbacks - 0
<script language="vbscript">
/*利用VBScript构建asc吗和字符串的互转函数*/
Function str2asc(strstr)
    str2asc = hex(asc(strstr))
End Function
Function asc2str(ascasc)
    asc2str = chr(ascasc)
End Function
</script>
<script language="javascript">
/*这里开始时UrlEncode和UrlDecode函数*/
function UrlEncode(str){
    var ret="";
    var strSpecial="!"#$%&'()*+,/:;<=>?[]^`{|}~%";
    for(var i=0;i<str.length;i++){
        var chr = str.charAt(i);
        var c=str2asc(chr);
        if(parseInt("0x"+c) > 0x7f){
            ret+="%"+c.slice(0,2)+"%"+c.slice(-2);
        }else{
            if(chr==" "){
                ret+="+";
            }else if(strSpecial.indexOf(chr)!=-1){
                ret+="%"+c.toString(16);
            }else{
                ret+=chr;
            }
        }
    }
    return ret;
}
function UrlDecode(str){
    var ret="";
    for(var i=0;i<str.length;i++){
        var chr = str.charAt(i);
        if(chr == "+"){
            ret+=" ";
        }else if(chr=="%"){
            var asc = str.substring(i+1,i+3);
            if(parseInt("0x"+asc)>0x7f){
                ret+=asc2str(parseInt("0x"+asc+str.substring(i+4,i+6)));
                i+=5;
            }else{
                ret+=asc2str(parseInt("0x"+asc));
                i+=2;
            }
        }else{
            ret+= chr;
        }
    }
    return ret;
}
</script>

 

posted on 2007-12-04 13:25 心。 阅读(1850) 评论(0)  编辑  收藏 所属分类: java

只有注册用户登录后才能发表评论。


网站导航: