当前位置: 首页 > 图文教程 > 网络编程 > ASP > asp中获取字符串中的时间字符串

ASP
ASP编程中15个非常有用的例子 (二)
ASP与JSP的比较(一)
ASP与JSP的比较(二)
ASP中五种连接数据库的方法
从ASP调用SQL中的图像
用排序串字段实现树状结构(例程:连接字串)
用排序串字段实现树状结构(例程:删除贴子)
用排序串字段实现树状结构(例程:回复表单)
用排序串字段实现树状结构(例程:显示贴子内容)
用排序串字段实现树状结构(例程:显示树)
用排序串字段实现树状结构(存储过程)
用排序串字段实现树状结构(库结构)
用排序串字段实现树状结构(原理)
remote script文档(转载自微软)(一)
remote script文档(转载自微软)(二)
remote script文档(转载自微软)(三)
remote script文档(转载自微软)(四)
remote script文档(转载自微软)(五)
remote script文档(转载自微软)(六)
remote script文档(转载自微软)(七)

ASP 中的 asp中获取字符串中的时间字符串


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 127 ::
收藏到网摘: n/a

由于时间在字符串中的值不一致性,会出现以下几中格式的字符串,没有办法用left,right,mid直接来获取,所以想到用正则表达式来实现这个功能(只要将这个功能改一下,就可以获取其他格式的字符串。


<%
'str = "2007-01-01 12:12:12 问题 1234"
'str="sdfd 01-01 12:12:12 问题"
'str="2007-01-01 12:12sdfdf"
'str="qqwq 01-01 13:14dddd"
str="a2007-01-01sdddd"

patrn="(\d+[-\:\s])+\d+"
Response.Write(RegExpTest(patrn,str))


Function RegExpTest(patrn, strng)
Dim regEx, Match, Matches   ' 建立变量。
Set regEx = New RegExp   ' 建立正则表达式。
regEx.Pattern = patrn   ' 设置模式。
regEx.IgnoreCase = True   ' 设置是否区分大小写。
regEx.Global = True   ' 设置全局替换。
Set Matches = regEx.Execute(strng)   ' 执行搜索。
For Each Match in Matches   ' 遍历 Matches 集合。
RetStr = Match.Value
Next
RegExpTest = RetStr
end Function
%>