如何从输入字符串中找到重复的整数,然后找到那些重复整数的总和?
到目前为止,我试图只从字符串中找到整数:
Function findInt(ByVal s As String) As String
Dim retStr As String
Dim i As Integer
retStr = ""
For i = 1 To Len(s)
If Mid(s, i, 1) >= "0" And Mid(s, i, 1) <= "9" Then
retStr = retStr + Mid(s, i, 1)
End If
Next
findInt = retStr
End Function
对不起,我是新来的,也是编程:)不知道这里的工作原理:))
感谢。
答案 0 :(得分:0)
遍历字符串并测试下一个字符是否与当前字符相同。
'1 form with:
' 1 textbox control: name=Text1
' 1 command button : name=Command1
Option Explicit
Private Sub Command1_Click()
Caption = FindDoubles(Text1.Text)
End Sub
Private Function FindDoubles(strText As String) As String
Dim lngIndex As Long
Dim strFind As String
Dim strDoubles As String
strDoubles = ""
For lngIndex = 1 To Len(strText) - 1
strFind = Mid$(strText, lngIndex, 1)
If Mid$(strText, lngIndex + 1, 1) = strFind Then
strDoubles = strDoubles & strFind & strFind & " "
End If
Next lngIndex
FindDoubles = strDoubles
End Function