Results 1 to 10 of 10

Thread: Find text between two characters

Hybrid View

  1. #1
    Hyperactive Member
    Join Date
    Oct 2013
    Posts
    389

    Re: Find text between two characters

    Code:
    Public Function GetBetween(ByRef sSearch As String, ByRef sStart As String, ByRef sStop As String, _
                                                        Optional ByRef lSearch As Long = 1) As String
        lSearch = InStr(lSearch, sSearch, sStart)
        If lSearch > 0 Then
            lSearch = lSearch + Len(sStart)
            Dim lTemp As Long
            lTemp = InStr(lSearch, sSearch, sStop)
            If lTemp > lSearch Then
                GetBetween = Mid$(sSearch, lSearch, lTemp - lSearch)
            End If
        End If
    End Function
    
    'Usage:Text1.Text =  Getbetween("123 get this 321","123","321")

  2. #2

    Thread Starter
    Junior Member
    Join Date
    Sep 2013
    Posts
    30

    Re: Find text between two characters

    Quote Originally Posted by Arnoutdv View Post
    Do you know the InStr method?
    It will return the location of a substring in a string.
    Yes i do, but I don't know wich tag will be used, I said <Name" just as an example... There are like 20+ tags, and I will not know wich one the user will use.

    Quote Originally Posted by Bonnie West View Post
    Whenever you want to find a substring within a string, you use either the InStr or InStrRev functions. Both functions returns the character position where the substring was located.

    So, what are you going to do once you've determined the position of those characters? Replace the text between them with something else? The Replace function can help you do that:


    Quote Originally Posted by stum View Post
    [code]Public Function GetBetween(ByRef sSearch As String, ByRef sStart As String, ByRef sStop As String, _
    But I'll not know wich tags has been used by the user...

Tags for this Thread

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