关于提取数字的问题!

moleboy 2003-04-07 12:35:01
我想要提取数字如下
110293-18765-09876
请问如何将 110293、18765、09876分别提取出来附值给变量A1,A2,A3!
使A1,A2,A3的值为A1=110293,A2=18765,A3=09876
...全文
17 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
YFY 2003-04-07
  • 打赏
  • 举报
回复
dim strSource as string
dim strResult(20) as string
dim strTmp as string
dim i as integer ,j as integer
dim A1 as string ,A2 as string ,A3 as string

strSource = 110293-18765-09876

i = 1
strResult(1) = ""

For j = 1 To len(strSource)
strTmp = Mid(strSource , j, 1)
If sTmp <> "-" Then
strResult(i) = strResult(i) & strTmp
Else
i = i + 1
strResult(i) = ""
End If
Next j

A1 = strResult(1)
A2 = strResult(2)
A3 = strResult(3)
zengjun1980 2003-04-07
  • 打赏
  • 举报
回复
dim a1,a2,a3 as string
dim ax() as string

ax=split("110293-18765-09876","-")

a1=ax(0)
a2=ax(1)
a3=ax(2)

Cooly(☆回答问题不要分儿☆)老兄,你很厲害!
AechoJohn 2003-04-07
  • 打赏
  • 举报
回复
dim strS as string
dim strWord() as string
strS = "110293-18765-09876"
strWord = split (strS,"-")
A1 = strWord(0)
A2 = strWord(1)
A3 = strWord(2)
czjw 2003-04-07
  • 打赏
  • 举报
回复
A="110293-18765-09876"
Txt = split(A,"-")
Cooly 2003-04-07
  • 打赏
  • 举报
回复
dim a1,a2,a3 as string
dim ax() as string

ax=split("110293-18765-09876","-")

a1=ax(0)
a2=ax(1)
a3=ax(2)
minajo21 2003-04-07
  • 打赏
  • 举报
回复
A1=Extract("110293-18765-09876","-",0)
A2=Extract("110293-18765-09876","-",1)
A3=Extract("110293-18765-09876","-",2)

Public Function Extract(Text As String, strSeparator As String, ByVal Index As Long) As String
Dim strColl As New VBA.Collection
Dim lngStart As Long 'the first place finding begin
Dim lngLoc As Long 'the position of ","
Dim lngLocPrev As Long
Dim blnEnd As Boolean

blnEnd = False
lngStart = 1
lngLocPrev = 0

Do While Not blnEnd
lngLoc = VBA.InStr(lngStart, Text, strSeparator)
If lngLoc <> 0 Then
If (lngLoc <> lngStart) Then
strColl.Add VBA.Mid(Text, lngStart, lngLoc - lngStart)
End If
lngStart = lngLoc + VBA.Len(VBA.Trim(strSeparator))
Else
strColl.Add VBA.Mid(Text, lngStart)
blnEnd = True
End If
Loop

If (0 <= Index) And (Index < strColl.count) Then
Extract = VBA.Trim(strColl.Item(Index + 1))
Else
Extract = ""
End If
Set strColl = Nothing
End Function
Cooly 2003-04-07
  • 打赏
  • 举报
回复
'Split函数

Split(expression[, delimiter[, limit[, compare]]])
fleshboy 2003-04-07
  • 打赏
  • 举报
回复
dim strArr() as string

strArr=split("110293-18765-09876","-")

A1=Val(strArr(0))
A2=Val(strArr(1))
A3=Val(strArr(2))


7,765

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧