'********************************************************************************************************** ' Name: startsWith ' Author: mielk | 2012-06-21 ' ' Comment: Checks if the given string starts with the specified prefix. ' ' Parameters: ' str String to be checked. ' prefix The prefix ' isCaseSensitive Optional parameter of Boolean type. ' It determines if text matching 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 string [str] starts with the given prefix. ' False - otherwise. ' ' ' --- Changes log ----------------------------------------------------------------------------------------- ' 2012-06-21 mielk Function created. '********************************************************************************************************** Public Function startsWith(str As String, prefix As String, Optional isCaseSensitive As Boolean = True) _ As Boolean Const METHOD_NAME As String = "startsWith" '------------------------------------------------------------------------------------------------------ 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 '| '----------------------------------------------------------------------------------------------------| '----------------------------------------------------------------------------------------------------| If VBA.StrComp(VBA.Left$(str, VBA.Len(prefix)), prefix, uCompareMethod) = 0 Then '| startsWith = True '| End If '| '----------------------------------------------------------------------------------------------------| End Function