asp cint clng的范圍與防止cint和clng的溢出解決方法大全
首先我們需要了解的是
cint范圍 -32,768 到 32,767。
clng范圍 -2,147,483,648 到 2,147,483,647。
cint與clng含義:
都可以強(qiáng)制將一個(gè)表達(dá)式轉(zhuǎn)換成數(shù)據(jù)類型
cint與clng處理數(shù)據(jù)的范圍:
CInt Integer -32,768 至 32,767,小數(shù)部分四舍五入。
CLng Long -2,147,483,648 至 2,147,483,647,小數(shù)部分四舍五入。
所謂溢出指的是超出處理數(shù)據(jù)的范圍,下面代碼是處理數(shù)據(jù)防止溢出的代碼,大家可以自己看看:
'檢測(cè)是否是短整數(shù)
sub Is_Int(string)
if len(abs(string))>10 then response.write "數(shù)據(jù)溢出":response.end
if instr(string,"-")<1 then
if cint(left(string,4))>3276 and cint(right(string,1))>7 then response.write "數(shù)據(jù)溢出":response.end
else
if cint(left(abs(string),4))>3276 and cint(right(string,1))>8 then response.write "數(shù)據(jù)溢出":response.end
end if
end sub
'檢測(cè)是否是長(zhǎng)整數(shù)
sub Is_Lng(string)
if len(abs(string))>10 then response.write "數(shù)據(jù)溢出":response.end
if instr(string,"-")<1 then
if clng(left(string,9))>214748364 and clng(right(string,1))>7 then response.write "數(shù)據(jù)溢出":response.end
else
if clng(left(abs(string),9))>21478364 and clng(right(string,1))>8 then response.write "數(shù)據(jù)溢出":response.end
end if
end sub
以下是一些檢驗(yàn)函數(shù),需要的朋友可以參考下:
第一種:
一、檢測(cè)它是不是整數(shù)
function Is_Int(a_str)
if not isnumeric(a_str) or len(str) > 5 then
Is_Int = false
exit function
elseif len(str) < 5 then
Is_Int = true
exit function
end if
if cint(left(a_str , 4)) > 3276 then
Is_Int = false
exit function
elseif cint(left(a_str , 4)) = 3276 and cint(right(a_str , 1)) > 7 then
Is_Int = false
exit function
else
Is_Int = true
exit function
end if
end function
二、檢測(cè)它是不是長(zhǎng)整數(shù)
function Is_Lng(a_str)
if not isnumeric(a_str) or len(str) > 10 then
Is_Lng = false
exit function
elseif len(str) < 10 then
Is_Lng = true
exit function
end if
if clng(left(a_str , 9)) > 214748367 then
Is_Lng = false
exit function
elseif clng(left(a_str , 9)) = 214748367 and clng(right(a_str , 1)) > 7 then
Is_Lng = false
exit function
else
Is_Lng = true
exit function
end if
end function
如果我們只需要是數(shù)子,其它的東西,都可以替換為空,下面這個(gè)是腳本之家站長(zhǎng)寫的一個(gè)正則,替換非數(shù)字的正則
function replacestr(str)
dim re
set re=new regexp
re.ignorecase=true
re.global=true
re.pattern="\D"
str=re.replace(str,"")
replacestr=str
set re=nothing
end function
下面是上面的調(diào)用方法
id=replacestr(id)
if len(id)>5 then id=left(id,5)
if id<>"" then id=clng(id)
if err.number<>0 Or id="0" then response.redirect "http://www.dbjr.com.cn"
dim rs
set rs=conn.execute("select id from news where id="&id&"")
相關(guān)文章
[教程+分享]具有良好體驗(yàn)度的Web注冊(cè)系統(tǒng)
[教程+分享]具有良好體驗(yàn)度的Web注冊(cè)系統(tǒng)...2007-07-07A利用ASP小偷和Google實(shí)現(xiàn)在線翻譯功能的代碼
A利用ASP小偷和Google實(shí)現(xiàn)在線翻譯功能的代碼...2007-11-11如何使用Administrators組用戶運(yùn)行ASP程序
如何使用Administrators組用戶運(yùn)行ASP程序...2007-01-01ASP UTF-8編碼下字符串截取和獲取長(zhǎng)度函數(shù)
截取文字長(zhǎng)度函數(shù),支持UTF-8 ,這樣就可以滿意大部分截取字符串的朋友了。2009-05-05ASP基礎(chǔ)入門第六篇(ASP內(nèi)建對(duì)象Request)
從本篇開(kāi)始作者從 ASP 內(nèi)建對(duì)象著手,為大家詳細(xì)剖析 ASP 的六個(gè)內(nèi)建對(duì)象和各種組件的特性和方法,需要的朋友可以參考下2015-10-10asp提示無(wú)效使用?Null:?Replace的解決方法
這篇文章主要介紹了asp提示無(wú)效使用?Null:?Replace,需要的朋友可以參考下2014-12-12