|
4#
楼主 |
发表于 2008-11-22 23:19:46
|
只看该作者
GLW提取方法一:运用了IsNumeric函数方法- Function tractstr(str As String) As String
- Dim i As Integer
- For i = 1 To Len(str)
- If IsNumeric(Mid(str, i, 1)) = True Then
- tractstr = tractstr & Mid(str, i, 1)
- End If
- Next i
- End Function
复制代码 提取方法二:VBS表达式方法- Function ReplaceStr(sourStr, patrn, replStr)
- Dim regEx As Object ' 建立变量
- Set regEx = CreateObject("vbScript.RegExp") ' 建立正则表达式
- regEx.Pattern = patrn ' 要找的字符串
- regEx.Global = True '全程查找(若非全程查找则只进行一次匹配)
- regEx.IgnoreCase = True ' 设置是否区分大小写
- ReplaceStr = regEx.Replace("" & sourStr & "", "" & replStr & "") ' 替换
- End Function
- '函数提取实例
- sourceText = "7中国0abc6美国英30国efg日22本韩国3"
- MsgBox ReplaceStr(sourceText, "[^0-9]", "")
复制代码 叶海峰Select Case语句方法- Dim i As Integer
- Dim str, str1 As String
- str = "7中国0abc6美国英30国efg日22本韩国3"
- For i = 1 To Len(str)
- Select Case Mid(str, i, 1)
- Case 0 To 9
- str1 = str1 & Mid(str, i, 1)
- End Select
- Next
复制代码
[ 本帖最后由 tanhong 于 2008-11-22 23:21 编辑 ] |
|