1.使用asp下载其他网页使用的函数:
function gethttppage(url)
dim adxmlhttp
set adxmlhttp = server.createobject("microsoft.xmlhttp")
adxmlhttp.open "get",url,false
adxmlhttp.send()
if adxmlhttp.readystate <> 4 then exit function
gethttppage = bytes2bstr(adxmlhttp.responsebody)
set adxmlhttp = nothing
End function
function bytes2bstr(vin)
dim bytesstream,stringreturn
set bytesstream = server.CreateObject("adodb.stream")
bytesstream.type = 2
bytesstream.open
bytesstream.writeText vin
bytesstream.position = 0
'bytesstream.charset = "gb2312"
bytesstream.charset = "utf-8"
bytesstream.position = 2
stringreturn = bytesstream.readtext
bytesstream.close
set bytesstream = nothing
bytes2bstr = stringreturn
end function
2.解决现实的网站中文乱码的问题:
例如采用GBK编码,就在文件的最上面加上 <%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
参考资料:http://www.cnblogs.com/net2/archive/2010/09/08/1821768.html
尝试指定IIS按什么编码读取。
<%@ codepage=65001%>UTF-8
<%@ codepage=936%>简体中文
<%@ codepage=950%>繁体中文
<%@ codepage=437 %>美国/加拿大英语
<%@ codepage=932 %>日文
<%@ codepage=949 %>韩文
<%@ codepage=866 %>俄文
codepage指定了IIS按什么编码读取。
例如采用UTF-8编码,就在文件的最上面加上 <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
3.设置asp异常显示到页面上:
%windir%\system32\inetsrv\appcmd set config -section:asp -scriptErrorSentToBrowser:true
参考资料:http://www.jb51.net/article/21927.htm
4.asp中使用正则表达式
4.1通用流程:
regex的属性: test,replace,match
Function RegExpTest(patrn, strng)
Dim regEx, retVal ' 建立变量。
Set regEx = New RegExp ' 建立正则表达式。
regEx.Pattern = patrn ' 设置模式。
regEx.IgnoreCase = False ' 设置是否区分大小写。
retVal = regEx.Test(strng) ' 执行搜索测试。
If retVal Then
RegExpTest = "找到一个或多个匹配。"
Else
RegExpTest = "未找到匹配。"
End If
End Function
参考资料:http://webcenter.hit.edu.cn/articles/2010/06-06/06173737.htm
4.2 matches的属性
4.2.1 循环遍历
for each match in matches
match.firstindex&match.value
4.2.2 matches的属性
(1).Matches对象 是否匹配到
使用Count属性,若>0则表示匹配到了
(2).SubMatches 提取要匹配字符串的关键属性,为一数组
若提取的部分(挎号所挎的部分)为一个,则取索引0,例如
- matches(0).SubMatches(0)
4.3 处理正则表达式中的中文
使用unicode即可;
将中文转化为unicode,放入表达式中。
5.asp中replace函数的使用
url=replace(url,string1,string2)
string1:source string;string2: string to replace the source
eg:
url = replace(url,"http","")
6.for循环使用
for each i in numbers
...
next