ASP與JavaScript的 String.Format 方法
2007-08-24 09:27
281 查看
因為習慣了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)
不過後來發現有人貼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)
相关文章推荐
- 为javascript添加String.Format方法
- 为javascript添加String.Format方法
- string.Format 里面包含 javascript方法参数的时候 单引号变成双引号的问题解决方法
- 给 Javascript 的 string 对象扩展一个 format 方法
- JavaScript里String.Format方法的实现
- asp.net开发有关DataFormatString的使用方法讲解
- javascript实现类似C# String的format方法
- 【ASP.NET】用JavaScript刷新框架子页面的8种方法
- javascript中Date format(js日期格式化)方法小结
- String.Format方法
- JAVA String.format 方法使用介绍
- Android中String资源文件的format方法
- javascript获取asp.net后台代码的方法
- javascript获取asp.net后台代码的方法
- 如何解决asp.net 在vs2010(.net framework 4.0)中listview控件用jquery,javascript为模版中的服务端控件注入事件的方法?因为vs2010在这个方面有存在的bug!
- Java String.Format() 方法及参数说明
- JavaScript中的字符串(String)的常用方法
- ASP.NET服务器端与javascript交互的一种方法
- String.Format()方法问题
- 在asp.net的方法里如何调用javascript的函数