string 转换 int
"sds#3435 " --> 3435
" " --> 0
" sd34sd34 " --.> 34
null --> 0
"sdfhghj " ---> 0
[解决办法]
- JScript code
function cInt(val){ if(val==null){ return 0; }else{ val=val.replace(/(^\s*)|(\s*$)/g, ""); if(isNaN(parseInt(val))) { while(isNaN(parseInt(val))&&val.length>0){ val=val.substring(1); if(!isNaN(parseInt(val))){ break; } } return isNaN(parseInt(val))?0:parseInt(val); }else{ return parseInt(val); } } } alert(cInt("sds#3435 ")); alert(cInt(" ")); alert(cInt(" sd34sd34 ")); alert(cInt(null)); alert(cInt("sdfhghj "));
[解决办法]
- VBScript code
s = "你的字串"if isnull(s) then s = ""Set re = New RegExpWith re .Pattern = "\D" .Global = True .IgnoreCase = TrueEnd Withs = trim(re.Replace(s, " ")) & " 0"ar = split(s)s2 = ar(0)if s2="" then s2 = "0"end ifresponse.write cint(s2)