October 27, 2003

ArrayShuffle – Shuffling the elements of an array of any type

‘ Shuffle the elements of an array of any type” Example:’ Dim arr As Integer() = {3, 7, 8, 2, 0, 9}’ ArrayShuffle(arr)’ Dim o As Object’ For Each o In arr’ Debug.Write(o & ” “)’ Next’ Debug.WriteLine(“”)Sub ArrayShuffle(ByVal arr As Array) Dim i, newIndex As Integer Dim tmpValue As

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””: ” &

ArrayListMerge – Merging two ArrayList avoiding duplicate values

‘ Merge two ArrayList, avoiding duplicate values (if there are already ‘ duplicate values in same input ArrayList however, they are not discarded)’ ‘ Example:’ Dim al1 As New ArrayList’ al1.Add(“John”)’ al1.Add(“Ann”)’ al1.Add(“Frank”)” Dim al2 As New ArrayList’ al2.Add(“Ann”)’ al2.Add(“Tony”)’ al2.Add(“Mark”)’ al2.Add(“John”)” Dim al3 As ArrayList = ArrayListMerge(al1, al2)’ Dim

ScrambleWords – Scrambling the words of the input string

‘ Scramble the words of the input string’ Note: requires the ArrayShuffle routine” Example:’ Dim text As String = “This is a test string for the ScrambleWords function”‘ Debug.WriteLine(ScrambleWords(text))Function ScrambleWords(ByVal text As String) As String Dim arr As String() = text.Split(” “c) ArrayShuffle(arr) Return String.Join(” “, arr)End Function

ArrayLastIndexOf – An extended version of Array.LastIndexOf

‘ An extended version of Array.LastIndexOf, with more options for string ‘ searches. The function returns the index of the found element,’ or -1 if no element is found” Example:’ Dim arr As String() = {“this is a string for my test”, “test number 2”,’ “another String”, “do you like

ArrayIndexOf – An extended version of Array.IndexOf

‘ An extended version of Array.IndexOf, with more options for string searches. ‘ The function returns the index of the found element,’ or -1 if no element is found” Example:’ Dim arr As String() = {“this is a string for my test”, “test number 2”,’ “another String”, “do you like