因為習慣了C#的 String.Format 去組合字串,最近在寫ASP與JavaScript時沒有這個功能實在是有夠不方便。
不過後來發現有人貼JavaScript方法,就以此方法改成ASP的
JavaScript:
String.format = function()
來源Blog
使用方式 : String.format('Hello. My name is {0} {1}.', firstName, lastName);
ASP
Function StringFormat(Source,Values,IsSQL)
If Source = null Or Not IsArray(Values) Then
StringFormat null
End If
For i = 0 To UBound(Values)
If IsSQL Then
Source = Replace(Source , "{" & i & "}",Replace(Values(i),"'","''"))
Else
Source = Replace(Source , "{" & i & "}",Values(i))
End IF
Next
StringFormat = Source
End Function
我有加上 是不是SQL 語法 替換 ' 成 二個 ' ,防止 SQL injection
使用方法 : StringFormat("Select * Form Account Where ID='{0}' AND PW='{1}'" , Array(ID,PW),true)
相关文章:
-
2021-11-03
-
2021-10-13
-
2021-07-07
-
2021-09-18
-
2022-12-23
-
2021-06-10
-
2021-06-25