Results 1 to 13 of 13

Thread: [RESOLVED] search & replace in notepad

Hybrid View

  1. #1
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: search & replace in notepad

    Try this:

    VB Code:
    1. Dim pos1 As Long, pos2 As Long, i As Long
    2. Dim file As String, line As String
    3.  
    4.     file = vbNullString
    5.    
    6.         Open "c:\test.txt" For Input As #1
    7.             Do While Not EOF(1)
    8.                 Line Input #1, line
    9.                     i = i + 1
    10.                     pos1 = InStr(1, line, "(")
    11.                     pos2 = InStr(1, line, ")")
    12.                    
    13.                         If pos1 > 0 And pos2 > 0 Then
    14.                             line = Left(line, pos1 - 1) & "(" & "replacement" & ")" & Right(line, Len(line) - pos2)
    15.                         End If
    16.                        
    17.                             If i = 1 Then
    18.                                 file = line
    19.                             Else
    20.                                 file = file & vbCrLf & line
    21.                             End If
    22.             Loop
    23.         Close #1
    24.        
    25.             Open "c:\test.txt" For Output As #1
    26.                 Print #1, file
    27.             Close #1

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    131

    Re: search & replace in notepad

    Yes Gavio but what if the word was (code)
    and where should i write the replacement ?

    sorry because i'm new in VB

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width