ASP
'宣告變數
Dim str0 ,str1 ,str2 ,inta ,intb
'指定資料
str0 = "ABC"
'斷行連接符號
:
常用範例 Dim str0 : str0 = "ABC"
'顯示資訊在畫面
response.write "str1=" & str1 & "</br>"
'顯示資訊在alert
response.write " <script language='JavaScript'> (window.alert('" & str1 & "')) </script> "
'暫停目前程式
response.end
'清除頁面顯示(緩衝區)資訊
response.clear
'強制送出緩衝區的資料
response.flush
'轉數字
inta = "1234"
intb = CInt(inta)'轉整數,-32768~32767
inta = "1234567"
intb = CLng(inta)'轉長整數,-2147483648~2147483647。
inta = "123.45"
intb = CDbl(inta)'轉浮點數(小數)
'四捨五入 FormatNumber(intA,intB)
inta = "1234.567"
intb = FormatNumber(inta,0) => 1235
intb = FormatNumber(inta,1) => 1324.6
intb = FormatNumber(inta,2) => 1234.57
'判斷數字
TrueFalse = Isnumeric(inta)
'字串函示
inta = "12345"
intb = CStr(inta)'強轉為字串
'取得字串的長度 Len(string)
inta = Len("ABC") => 3
'取得字串內容反轉後的結果 StrReverse(string)
str1="ABCdef123"
str2 = StrReverse(str1) => "321fedCBA"
'取代置換 Replace(string, string, string)
str1 = Replace("2020/11/20", "/", "-" ) => "2020-11-20"
'去掉字串的右邊空白部分 Rtrim(string)
str2 = Rtrim(" ABC ") = > " ABC"
'去掉字串的左邊空白部分 Ltrim(string)
str2 = Rtrim(" ABC ") = > "ABC "
'由字串左邊開始取得N位 Left(string, intLength)
str1 = Left("ABCDEFG", 3) => "ABC"
'由字串右邊開始取得N位 Right(string, intLength)
str1 = Right("ABCDEFG", 3) => "EFG"
'指定取得中間的字串 Mid(string, intLength, intLength)
str1 = Mid("ABCD", 1, 2) => "AB"
'取消第一個字元 Right(string, Len(string)-1)
str2 = "ABCD"
str1 = Right(str2, Len(str2)-1) => "BCD"
'取消最後一個字元 Left(string, Len(string)-1)
str2 = "ABCD"
str1 = Left(str2, Len(str2)-1) => "ABC"
'前後各取消1位元 Mid(string, 2, Len(string)-2)
str2 = "ABCD"
str1 = Mid(str2, 2, Len(str2)-2) => "BC"
'函示格式
Function xxxAxxx ()
...
End Function
'呼叫函示
str1 = xxxAxxx()
'亂數 rnd
randomize(time) '取亂數種子
inta = (int(rnd*2)) => 0 ~ 1 隨機出現
'判斷
if (inta < intB) then
...
end if
'迴圈
for i=0 to 100
...
Next
'讀檔案 '讀0001.html的檔案內容
Set str0 = Server.CreateObject("Scripting.FileSystemObject").OpenTextFile( Server.MapPath("0001.html") )
response.write str0.readall
'寫檔案
dim fs, f
dim strFile : strFile = server.mappath("\webinar\include\RecordLogLinkingpage.txt") '指定路進
set fs=Server.CreateObject("Scripting.FileSystemObject") 'Creat filesystemobject 物件
if fs.FileExists(strFile) then '若檔案存在
set f=fs.OpenTextFile(server.MapPath("RecordLogLinkingpage.txt"),8,false,-2) '準備寫檔案
f.WriteLine("AAA")
f.WriteLine("BBB")
f.Close
set f=nothing
end if
set fs=nothing
'時間間格多久 'd=天,h=時,n=分
dim DateA = "2020/01/03 23:00:00"
dim DateB = "2020/01/03 23:05:00"
intA = datediff("n", DateA, DateB) => 5
'時間比較
if (datediff("n", DateA, DateB)>0) then
...
end if
'產生亂數字串
tmpstr = "0123456789abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"
randomize
randstr=""
for j=1 to 5
randstr = randstr & mid(tmpstr,int(62*rnd+1),1)
next
'判斷是否為陣列
TrueFalse = IsArray(Data)
'得到陣列大小 ubound(ArrA,intA)
inta = ubound(ArrA,1) '一為陣列
intb = ubound(ArrB,2) '二為陣列
'用逗號分開資訊 Split("字符串","分割符")
ArrA = Split("AB,CDE,FG,HIJK" , ",")
'陣列宣告和使用
arrParamData = Array("AAA","BBB")
'靜態陣列的宣告和使用
Dim NameArray(1, 1, 2)
NameArray(0, 1, 0) = "趙錢孫"
'宣告動態陣列
Dim name()
'宣告陣列大小
ReDim name(2)
'指定陣列值
name(0) = "趙錢孫"
name(2) = "張無忌"
'更改陣列大小
ReDim Preserve name(4)
name(3) = "楊過"
'取陣列單一值
str1 = name(3)
'取IP
str1 = Request.ServerVariables("SERVER_NAME")
'取網址
str1 = request.servervariables("http_referer") => 前頁面網址
str1 = request.servervariables("script_name") => 本頁面網址
'設定網頁逾時時間
Server.ScriptTimeout = 5
'錯誤繼續不中斷
On Error Resume Next
我只是一棵樹