在这样的字符串中,怎么提取前面的数字
在这样的字符串中,如何提取前面的数字?
我现在字段里有这样的字符串,如:1 x535,1 x 535L,1x 5204,2 x 4345这样的字符串里,如何提取得到最前面的数字。因为这个数字后跟空格,再跟x,再有空格?是不是字符串匹配的内容?
------解决方案--------------------
试试:CStr(Val("1 x535"))
------解决方案--------------------
我现在字段里有这样的字符串,如:1 x535,1 x 535L,1x 5204,2 x 4345这样的字符串里,如何提取得到最前面的数字。因为这个数字后跟空格,再跟x,再有空格?是不是字符串匹配的内容?
------解决方案--------------------
试试:CStr(Val("1 x535"))
------解决方案--------------------
Private Sub Form_Load()
Dim dic As Object, tmp
Dim strData As String
Dim reg As Object
Dim matchs As Object, match As Object
strData = "1 x 5503,2x 3402" & vbCrLf & _
"2 x 231" & vbCrLf & _
"1 x 4602" & vbCrLf & _
"1 x 2121" & vbCrLf & _
"1 x 1290" & vbCrLf & _
"2 x 5503" & vbCrLf & _
"1 x 4602" & vbCrLf & _
"1 x 2121" & vbCrLf & _
"1 x 231"
Set dic = CreateObject("scripting.dictionary")
Set reg = CreateObject("vbscript.regExp")
reg.Global = True
reg.Pattern = "(\d+)\s*x\s*(\d+)"
Set matchs = reg.Execute(strData)
For Each match In matchs
dic(match.SubMatches(1)) = dic(match.SubMatches(1)) + Val(match.SubMatches(0))