'********************************************************************************************************** ' Name: contains ' Author: mielk | 2014-09-20 ' ' Description: Function to check if the given string contains substring given as a second ' parameter. ' ' Parameters: ' baseString Base string that will be searched. ' lookFor Substring the function is looking for in the base string. ' isCaseSensitive Optional parameter of Boolean type. ' It determines if text searching is case sensitive. ' * If this value is set to True, searching is case sensitive - a letter in lowercase ' is treated as different than the same letter in uppercase (i.e. a ? A). ' * If this value is set to False, it doesn't matter if a letter is in lowercase or ' in uppercase, since both of them are considered as the same character ' (i.e. a = A). ' * Default value of this parameter is True. ' ' ' Returns: ' Boolean True - if the given substring is contained in the specified base text. ' False - otherwise. ' ' ' ' --- Changes log ----------------------------------------------------------------------------------------- ' 2014-09-20 mielk Function created. '********************************************************************************************************** Public Function contains(baseString As String, lookFor As String, _ Optional isCaseSensitive As Boolean = False) As Boolean Const METHOD_NAME As String = "contains" '------------------------------------------------------------------------------------------------------ Dim uCompareMethod As VBA.VbCompareMethod '------------------------------------------------------------------------------------------------------ 'Convert [isCaseSensitive] parameter of Boolean type to the [VbCompareMethod] enumeration. ----------| If isCaseSensitive Then '| uCompareMethod = VBA.vbBinaryCompare '| Else '| uCompareMethod = VBA.vbTextCompare '| End If '| '----------------------------------------------------------------------------------------------------| 'Check if substring is contained in base string by using VBA built-in function VBA.InStr. -----------| contains = (VBA.InStr(1, baseString, lookFor, uCompareMethod) > 0) '| '----------------------------------------------------------------------------------------------------| End Function