怎么将text1.text内指定的内容按下命令按钮后保留,删除不需要的内容
比如text1.text的内容是
  1111 5 2222  3333 444 1111 5 2222........
  1111 5 2222  3333 444 1111 5 2222........
   1111 5 2222  3333 444 1111 5 2222........要保留1111  2222之间的内容(那个5)删除其他不需要的  

解决方案 »

  1.   

    Option ExplicitPrivate Sub Command1_Click()
    Dim i As Integer
    Dim s As String
    For i = 1 To 3
    s = String(4, 48 + i)
    Debug.Print s
    Text1 = Replace(Text1, s, "")
    Next
    Text1 = Replace(Text1, 444, "")
    Text1 = Replace(Text1, "........", "")
    End Sub
      

  2.   

    我希望的是删除1111前面的字符和删出2222后面的字符,保留1111和2222之间的字符!!是字符!!不一定是数字有可能是英文后者中文!!如AAAA 不 BBBB  如2 我要我想 看  人人人我  这些1111和2222可以写在text2和text3
      

  3.   

    先谢谢您啊!
    那些444和只是个例子 又可能是8ncmdhfj 和515sadkkoh 等不规则的数 但是1111和2222是规则的数!!我是想保留下1111和2222之间的数!删除其他不规则的数!
      

  4.   

    试试
    Private Sub Command1_Click()
        Dim str As String
        Dim s1() As String
        Dim s2() As String
        Dim idx As Integer
        Dim bln As Boolean
        
        str = Text1
        
        Do While InStr(str, Space(2)) > 0
            str = Replace(str, Space(2), Space(1))
        Loop
        
        s1 = Split(str, Space(1))
        ReDim s2(0)
        For idx = 1 To UBound(s1) - 1
            If s1(idx - 1) = "11111" And s1(idx + 1) = "22222" Then
                If bln Then
                    ReDim Preserve s2(UBound(s2) + 1)
                Else
                    bln = True
                End If
                s2(UBound(s2)) = s1(idx)
            End If
        Next
        
        Text2 = Join(s2, Space(1))
    End Sub
      

  5.   

    可以简便一点。窗体控件Text1、Text2、Command1
    Private Sub Command1_Click()
    Dim a$
    ss = Split(Form1.Text1.Text, "1111 ")
    For i = 0 To UBound(ss)
        s = Split(ss(i), Space(1)): a = a & s(0)
    Next i
    Form1.Text2.Text = a
    End Sub