在记事本上如下字符
$$abcd
efs
fdsa
fdr##
sdfe
fdsa
fdsa
$$abc##
fdasj=--------------=
不关有没有换行符,$$和##之间的字符都替换为AAA的程序怎么写?
要求是两种,第一不用正则,第二用正则
谢谢

解决方案 »

  1.   


    i=instr(1,str,"$$")
    j=instr(i,str,"##")
    str=left(str,i+1) & "AAA" & mid(str,j)  
    *****************************************************************************
    欢迎使用CSDN论坛阅读器 : CSDN Reader(附全部源代码) 
    http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html
      

  2.   

    Option ExplicitDim str As String
    Private Sub Command1_Click()
    Dim str_Temp As String
    Dim int_Temp As Integer
    Dim Pos1 As Integer
    Dim Pos2 As IntegerOpen "D:\aa.txt" For Input As #1
      Do While EOF(1) = False
        Line Input #1, str_Temp
        str = str & str_Temp
      Loop
    Close #1
       Pos1 = InStr(1, str, "$$")
       If Pos1 = 0 Then
          MsgBox "Have not any will be changed"
          Exit Sub
       End If
       Pos2 = InStr(Pos1, str, "##")
       
       
    Do While Pos1 <> 0 And Pos2 <> 0
       str = ChangeChar(Pos1, Pos2, str)
       Pos1 = InStr(Pos2, str, "$$")
       If Pos1 = 0 Then Exit Do
       Pos2 = InStr(Pos1, str, "##")
     Loop
    Debug.Print str
    End Sub
    Public Function ChangeChar(p1 As Integer, p2 As Integer, str As String) As String
       ChangeChar = Left(str, p1 + 1) & String(p2 - p1 - 2, "A") & Mid(str, p2)
       
    End Function