Results 1 to 6 of 6

Thread: Searching and Replacing then...

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216

    Talking Searching and Replacing then...

    OK here's the deal...
    I know how to find the first occurence of a string using Instr BUT
    how can I increment through a document and eliminate all </font> tags after I find my starting point then leaving the last one intact?

    from this:

    document words are here with other </font> tags but I don't
    want to erase these. I want to erase the ones' below
    this marker >i.

    yadayadayada</font>
    yadayadayada</font>
    yadayadayada</font>
    yadayadayada</font>

    to this:

    document words are here with other </font> tags but I don't
    want to erase these. I want to erase the ones' below
    this marker >i.

    yadayadayada
    yadayadayada
    yadayadayada
    yadayadayada</font>

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216
    anyone???

  3. #3
    pathfinder NotLKH's Avatar
    Join Date
    Apr 2001
    Posts
    2,397
    How 'Bout This:

    The following code relies on having a command1 button on a
    form, and its click event illustrates how to use the function
    REPLACE_ALL_BUT_LAST, which should be what you want.

    Code:
    Private Sub Command1_Click()
    MY_IN = " A 1 B1 C1C DD 11 EE"
    MsgBox MY_IN & Chr$(13) & REPLACE_ALL_BUT_LAST(MY_IN, "1", "")
    End Sub
    
    Private Function REPLACE_ALL_BUT_LAST(ByVal MY_SOURCE As String, ByVal REPLACE_WHAT As String, ByVal REPLACE_WITH As String) As String
    Dim MY_COUNT As Long
    MY_COUNT = 0
    Dim MY_SPOT As Long
    MY_SPOT = InStr(1, MY_SOURCE, REPLACE_WHAT, vbTextCompare)
    If MY_SPOT = 0 Then
        MsgBox REPLACE_WHAT & " Not Found!"
    Else
        While MY_SPOT <> 0
            MY_COUNT = MY_COUNT + 1
            MY_SPOT = InStr(MY_SPOT + 1, MY_SOURCE, REPLACE_WHAT, vbTextCompare)
        Wend
        MY_COUNT = MY_COUNT - 1
        MY_SOURCE = Replace(MY_SOURCE, REPLACE_WHAT, REPLACE_WITH, 1, MY_COUNT, vbTextCompare)
    End If
    REPLACE_ALL_BUT_LAST = MY_SOURCE
    End Function

    -Hope This Helps
    -Lou

  4. #4
    Hyperactive Member
    Join Date
    May 2000
    Location
    Or
    Posts
    316
    I like what was posted above (probably more flexible), but this would also work.

    VB Code:
    1. '***************************************************
    2. 'I've pasted the string that you need to work with
    3. 'into a textbox call text1, so this is where I am getting the data.
    4. '***************************************************
    5. Private Sub Command1_Click()
    6. Dim tmp_string As String
    7. Dim end_position As Long
    8.  
    9. 'Find the last occurance of </font> in your string
    10. end_position = InStrRev(Text1.Text, "</font>")
    11. 'Grab all text up to the last occurrance and replace </font> with nothing
    12. tmp_string = Replace$(Mid$(Text1.Text, 1, end_position - 1), "</font>", "")
    13. 'Reconstruct your string
    14. Text1.Text = tmp_string & Mid$(Text1.Text, end_position)
    15.  
    16. End Sub

    Hope this helps

  5. #5
    pathfinder NotLKH's Avatar
    Join Date
    Apr 2001
    Posts
    2,397
    Thanks for the Appreciation, reeset!

    I've just got to get started using the mid function someday!
    It Definetely seems to make life easier!

    -Lou

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216
    thanks for the replies I will use them!


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