|
-
Jun 15th, 2001, 09:20 AM
#1
Thread Starter
PowerPoster
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>
-
Jun 15th, 2001, 09:37 AM
#2
Thread Starter
PowerPoster
-
Jun 15th, 2001, 10:07 AM
#3
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
-
Jun 15th, 2001, 10:24 AM
#4
Hyperactive Member
I like what was posted above (probably more flexible), but this would also work.
VB Code:
'***************************************************
'I've pasted the string that you need to work with
'into a textbox call text1, so this is where I am getting the data.
'***************************************************
Private Sub Command1_Click()
Dim tmp_string As String
Dim end_position As Long
'Find the last occurance of </font> in your string
end_position = InStrRev(Text1.Text, "</font>")
'Grab all text up to the last occurrance and replace </font> with nothing
tmp_string = Replace$(Mid$(Text1.Text, 1, end_position - 1), "</font>", "")
'Reconstruct your string
Text1.Text = tmp_string & Mid$(Text1.Text, end_position)
End Sub
Hope this helps
-
Jun 15th, 2001, 10:32 AM
#5
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
-
Jun 15th, 2001, 10:33 AM
#6
Thread Starter
PowerPoster
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|