-
im making a program that has alot to do with text replaces ment and im not good at all that stuff so can some one help me out . i got two question
1) How can i replace the text and then replace it with something else
ex
<title> hehehehehhehe </title>
<title> replace that </title> ' with out making a new title tag
2) how can i get the text that is inside the tags
ex
<title> hehehehhehehhehe </title>
teh title is heheheheheheheh
if any one anwser's just one it will be very nice i now this text stuff is hard thank you
-
2 functions
1) give the Replace function a try
2) give the InStr function a try
hope it helps
-
maybe if i knew how to use them i whould and i thinkw hat im trying to do is not with the replace function because the title can have anytrhing in side the tag ex
<title> anything ins ide this </title>
<title> now what i want to replace </title>
-
This will get the text out of <TITLE> and </TITLE> (or whatever you specify)
Code:
Function GetText(sIn As String, sEnclosedIn As String, sEnclosedIn2 As String) As String
Dim StartPos As Integer, EndPos As Integer
StartPos = InStr(1, sIn, sEnclosedIn) + Len(sEnclosedIn)
EndPos = InStr(StartPos, sIn, sEnclosedIn2) - (Len(sEnclosedIn) + 1)
GetText = Mid(sIn, StartPos, EndPos)
End Function
Private Sub Command1_Click()
Dim MyString As String
MyString = "<TITLE>Text inside title</TITLE>"
Print GetText(MyString, "<TITLE>", "</TITLE>")
End Sub
-
<?>
Code:
Option Explicit
Private Sub Command1_Click()
Dim myString As String, temp1 As String, temp2 As String
myString = "<title> hehehehehhehe </title>"
temp1 = Left(myString, 7)
temp2 = Right(myString, 8)
myString = ""
myString = temp1 & "My Replacement" & temp2
MsgBox myString
End Sub
-
thanks guy and thank you HESAIDJOE alor because you heped me out both times
-
A little more, using Megatron's code:
Code:
Function GetText(sIn As String, sEnclosedIn As String, sEnclosedIn2 As String) As String
Dim StartPos As Integer, EndPos As Integer
StartPos = InStr(1, sIn, sEnclosedIn) + Len(sEnclosedIn)
EndPos = InStr(StartPos, sIn, sEnclosedIn2) - (Len(sEnclosedIn) + 1)
GetText = Mid(sIn, StartPos, EndPos)
End Function
Private Sub Command1_Click()
Dim MyString As String
MyString = "<TITLE>BIG TITLE STRING IN BETWEEN WORDS</TITLE>"
MyNewString = GetText(MyString, "<TITLE>", "</TITLE>")
Debug.Print Replace(MyString, MyNewString, "Let-me-squeeze-in-here")
End Sub
Just a little advancement using vb6's Replace function. Hope that helps a bit more.