如何截取文字中的数字?

phuai007 2008-12-05 03:31:20
格式为:
岁月风云-国语字幕50集
岁月风云-国语字幕50

岁月风云-国语字幕05集
岁月风云-国语字幕50

我只要这个50或者05,其他都不要,用什么函数来获取呢?
...全文
126 点赞 收藏 30
写回复
30 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
zjzb0409 2008-12-05
不错。
回复
df274119386 2008-12-05
[Quote=引用 2 楼 xming4321 的回复:]
遍历所有的字符
判断是不是数字

当然用正则表达式更好
[/Quote]

正则好
回复
[Quote=引用 26 楼 virgo2008 的回复:]
汗,是藏故意的还是看错的啊!没有注意!
[/Quote]

我是为了让他看到效果,加逗号的
回复
wackyboy 2008-12-05

Dim a,b,ma
a="岁月风云-国语字幕50集,岁月风云-国语字幕50,岁月风云-国语字幕05集,岁月风云-国语字幕50"

set ma=new regexp
ma.global=true
ma.pattern="[^\d]"
b=ma.replace(a,"") ' 结果:50500550
回复
virgo2008 2008-12-05
汗,是藏故意的还是看错的啊!没有注意!
回复
virgo2008 2008-12-05
rv1=split(rv,",")
for i=0 to ubound(rv1)-1 多一个,号,后面截取的占用了一个数组位置
rv2=rv2&" "&rv1(i)
next
response.write rv2
回复
phuai007 2008-12-05
搞定了,将 rv = re.Replace(ss,"$2,") 后面的$2后面那个逗号去掉就行了, 多谢2位
回复
virgo2008 2008-12-05
rv1=split(rv,",")
for i=0 to ubound(rv1)
rv2=rv2&" "&rv1(i)
next
response.write rv2
回复
phuai007 2008-12-05
[Quote=引用 18 楼 chinmo 的回复:]
HTML code<%ss = "岁月风云-国语字幕10集,岁月风云-国语字幕20,岁月风云-国语字幕30集,岁月风云-国语字幕40"
Set re = New RegExp
re.Pattern = "([^\d]*)(\d)([^\d]*)"
re.Global = True
re.IgnoreCase = True
re.MultiLine = True
rv = re.Replace(ss,"$2,")
response.Write rv%>



这个才对

那个看错了
[/Quote]

用了这个,数字出来了,不过多了一个逗号,如 50, 40, 等 数字后面多了个逗号
回复
phuai007 2008-12-05
[Quote=引用 18 楼 chinmo 的回复:]
HTML code<%ss = "岁月风云-国语字幕10集,岁月风云-国语字幕20,岁月风云-国语字幕30集,岁月风云-国语字幕40"
Set re = New RegExp
re.Pattern = "([^\d]*)(\d)([^\d]*)"
re.Global = True
re.IgnoreCase = True
re.MultiLine = True
rv = re.Replace(ss,"$2,")
response.Write rv%>



这个才对

那个看错了
[/Quote]

用了这个,数字出来了,不过多了一个逗号,如 50, 40, 等 数字后面多了个逗号
回复
phuai007 2008-12-05
[Quote=引用 15 楼 chinmo 的回复:]
HTML code<%ss = "岁月风云-国语字幕10集,岁月风云-国语字幕20,岁月风云-国语字幕30集,岁月风云-国语字幕40"
Set re = New RegExp
re.Pattern = "([^\d]*)\d([^\d]*)"
re.Global = True
re.IgnoreCase = True
re.MultiLine = True
rv = re.Replace(ss,"$1,")
response.Write rv%>
[/Quote]

用了这个代码,文字出来了,数字没了,和目的相反,我只要数字不要文字...
回复
<%ss = "岁月风云-国语字幕10集,岁月风云-国语字幕20,岁月风云-国语字幕30集,岁月风云-国语字幕40"
Set re = New RegExp
re.Pattern = "([^\d]*)(\d+)([^\d]*)"
re.Global = True
re.IgnoreCase = True
re.MultiLine = True
rv = re.Replace(ss,"$2,")
response.Write rv%>
回复
<%ss = "岁月风云-国语字幕10集,岁月风云-国语字幕20,岁月风云-国语字幕30集,岁月风云-国语字幕40"
Set re = New RegExp
re.Pattern = "([^\d]*)(\d)([^\d]*)"
re.Global = True
re.IgnoreCase = True
re.MultiLine = True
rv = re.Replace(ss,"$2,")
response.Write rv%>


这个才对

那个看错了
回复
phuai007 2008-12-05
多谢virgo2008 ,不过问题还没解决,我将上面的代码搬上去了,出现js错误,提示缺少对象
回复
virgo2008 2008-12-05
[Quote=引用 15 楼 chinmo 的回复:]
HTML code<%ss = "岁月风云-国语字幕10集,岁月风云-国语字幕20,岁月风云-国语字幕30集,岁月风云-国语字幕40"
Set re = New RegExp
re.Pattern = "([^\d]*)\d([^\d]*)"
re.Global = True
re.IgnoreCase = True
re.MultiLine = True
rv = re.Replace(ss,"$1,")
response.Write rv%>
[/Quote]
藏的更加适合你,你是喜欢在vbscript里面判断的,就用他的就可以了!
回复
<%ss = "岁月风云-国语字幕10集,岁月风云-国语字幕20,岁月风云-国语字幕30集,岁月风云-国语字幕40"
Set re = New RegExp
re.Pattern = "([^\d]*)\d([^\d]*)"
re.Global = True
re.IgnoreCase = True
re.MultiLine = True
rv = re.Replace(ss,"$1,")
response.Write rv%>
回复
virgo2008 2008-12-05

<script language="javascript">
function aa(x)
{
str1=x.replace(/\D/g," ")
document.write(str1)
}
</script>


<%
function GetNo(iGameID) '获得集数
szSQL = "SELECT FullPath FROM Prog_Server where Prog_ID=" & iGameID
Set rsData_RName = Server.CreateObject("ADODB.Recordset")
rsData_RName.Open szSQL,con,1,3
if not rsData_RName.EOF then
FullPath = rsData_RName("FullPath")
m = InStrRev(FullPath, "\")
FullPath = Right(FullPath, Len(FullPath) - m)
n = InStr(FullPath, ".")
FullPath = Left (FullPath, n-1)

End If
rsData_RName.Close
set rsData_RName = nothing
GetNo=str1
Response.Write " <script>aa('"&FullPath&"') </script>"
end function

%>
回复
phuai007 2008-12-05

function GetNo(iGameID) '获得集数
szSQL = "SELECT FullPath FROM Prog_Server where Prog_ID=" & iGameID
Set rsData_RName = Server.CreateObject("ADODB.Recordset")
rsData_RName.Open szSQL,con,1,3
if not rsData_RName.EOF then
FullPath = rsData_RName("FullPath")
m = InStrRev(FullPath, "\")
FullPath = Right(FullPath, Len(FullPath) - m)
n = InStr(FullPath, ".")
FullPath = Left (FullPath, n-1)

End If
rsData_RName.Close
set rsData_RName = nothing
response.Write"<script language=""javascript"">"
response.Write"var str="&FullPath&""
response.Write"str1=str.replace(/\D/g,"""");"
response.Write "document.write(str1);"
response.Write"</script>"
GetNo=str1
end function

才看清楚是用js,不过我这样写代码以后,什么都没获取到,提示 str为空或不是对象,帮忙修改下
回复
virgo2008 2008-12-05
贴下你的代码!
回复
phuai007 2008-12-05
用楼上的方法出现错误:

语法错误

/webmedia/common/dbend.inc.asp,行 423

str1=str.replace(/\D/g," ")
-----------------^
回复
加载更多回复
相关推荐
发帖
ASP
创建于2007-09-28

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
帖子事件
创建了帖子
2008-12-05 03:31
社区公告
暂无公告