Visual Basic 6 function "strstr"

Go back

Below you'll find the source for the Visual Basic 6 function strstr.

Attribute VB_Name = "modStrstr"
' This function is downloaded from:
' http://www.stefanthoolen.nl/archive/vb6-functions/
' 
' You may freely distribute this file but please leave all comments, including this one, in it.
' 
' @Author Stefan Thoolen <mail@stefanthoolen.nl>

Option Explicit

''
' Searches for a string in another string and gives all data from that point
' Same syntax as the PHP function 'strstr'
' See also: http://www.php.net/manual/en/function.strstr.php
' @param    String  haystack        The full string we want to search
' @param    String  needle          The part we need
' @return   String                  All characters including and following the needle
' @author   Stefan Thoolen <mail@stefanthoolen.nl>
Public Function strstr(haystack As String, needle As String) As String
    Dim i As Integer, ret As String
    For i = 1 To Len(haystack)
        If Mid(haystack, i, Len(needle)) = needle Then ret = Mid(haystack, i, Len(haystack) - i + 1): i = Len(haystack)
    Next i
    strstr = ret
End Function