Results 1 to 7 of 7

Thread: Text and string

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 1999
    Posts
    204
    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. #2
    Addicted Member
    Join Date
    Oct 1999
    Location
    Brossard, Québec, Canada
    Posts
    241

    Thumbs up 2 functions

    1) give the Replace function a try

    2) give the InStr function a try

    hope it helps

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 1999
    Posts
    204
    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>
    WHat would we do with out Microsoft.
    A lot more.

  4. #4
    Guest
    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

  5. #5
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    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
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jan 1999
    Posts
    204
    thanks guy and thank you HESAIDJOE alor because you heped me out both times
    WHat would we do with out Microsoft.
    A lot more.

  7. #7
    Guest
    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.

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