+ -
当前位置:首页 → 问答吧 → 如何快速去掉单位只取数字?

如何快速去掉单位只取数字?

时间:2011-09-23

来源:互联网

233 元/月
比如这个,只取 前面的 这里是233,但不一定是数字,有可能是其他字符

作者: phuai007   发布时间: 2011-09-23

substring()截取字符串。。。

作者: zsx841021   发布时间: 2011-09-23

自己写出来了

VB code

'编辑的时候去掉单位
Function dell_dw(str)
str1=split(str," ")
dell_dw=str1(0)
End function

作者: phuai007   发布时间: 2011-09-23

VBScript code

  function getNum(str)
    Dim re : set re = new RegExp
    re.Pattern = "[^\d]*"
    re.IgnoreCase = True
    re.Global = True
    getNum = re.replace(str,"")
  end function
str = "233 元/月"
response.write getNum(str)


楼主试试

作者: calmcrime   发布时间: 2011-09-23

用正则表达式可以解决
<%
str="233&nbsp;元/月"
str=strFilter(str)
function strFilter(strsource)
Set obRegexp=New RegExp
obRegexp.IgnoreCase=True
obRegexp.Global=True
obRegexp.Pattern="[^0-9]*"
strsource=obRegexp.Replace(strsource,"")
Set obRegexp = Nothing  
strFilter=strsource
end function
%>

作者: zhux2003   发布时间: 2011-09-23

楼上都正解~~~~~

作者: enjoy_gw   发布时间: 2011-09-23