日期:2014-05-17 浏览次数:20951 次
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 "));
------解决方案--------------------
s = "你的字串" if isnull(s) then s = "" Set re = New RegExp With re .Pattern = "\D" .Global = True .IgnoreCase = True End With s = trim(re.Replace(s, " ")) & " 0" ar = split(s) s2 = ar(0) if s2="" then s2 = "0" end if response.write cint(s2)