ArrayCountOccurrences – Count the occurrences of a string within the input array

' Return the number of occurrences found in the input array,'  with the specified search options'' Example:'   Dim arr As String() = {"this is a string for my test", "test number 2",'  "another String", "do you like this string?", "I like running tests"}'   Debug.WriteLine("Number of occurrences for ""string"": " & '       ' ArrayCountOccurrences(arr, "string", 0, True, False)) ' => 2Function ArrayCountOccurrences(ByVal arr As String(), _    ByVal search As String) As Integer    Return ArrayCountOccurrences(arr, search, arr.GetLowerBound(0))End Function' this overloaded version allows you to specify also the array's index to start ' fromFunction ArrayCountOccurrences(ByVal arr As String(), ByVal search As String, _    ByVal startIndex As Integer) As Integer    Return ArrayCountOccurrences(arr, search, startIndex, True)End Function' this overloaded version allows you to specify also whether the search is case-' sensitiveFunction ArrayCountOccurrences(ByVal arr As String(), ByVal search As String, _    ByVal startIndex As Integer, ByVal caseSensitive As Boolean) As Integer    Return ArrayCountOccurrences(arr, search, startIndex, caseSensitive, True)End Function' this overloaded version allows you to specify also whether only exact matches ' are validFunction ArrayCountOccurrences(ByVal arr As String(), ByVal search As String, _    ByVal startIndex As Integer, ByVal caseSensitive As Boolean, _    ByVal exactMatch As Boolean) As Integer    Dim count As Integer = 0    Dim i As Integer = startIndex - 1    ' keep calling the ArrayIndexOf function with the startIndex of the last     ' occurrence's index + 1, until it returns -1    Do        i = ArrayIndexOf(arr, search, i + 1, caseSensitive, exactMatch)        If i > -1 Then count += 1    Loop While i > -1    Return countEnd Function

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS