' ' Sorting test of strings ' ' Problem: How to sort strings, on a Name inside the string ' ' 2017.08.26 Peter Svard ' Cls ' Dim m$(10) As string m$(1)= "Knr: 151, Tom, No: 50, blablabla" m$(2)= "Knr: 292, Phil, No: 75, blablabla" m$(3)= "Knr: 313, Anna, No: 80, blablabla" m$(4)= "Knr: 424, Harry, No: 56, blablabla" m$(5)= "Knr: 155, Lisa, No: 37, blablabla" m$(6)= "Knr: 235, Carl, No: 49, blablabla" m$(7)= "Knr: 372, Greg, No: 51, blablabla" m$(8)= "Knr: 168, Will, No: 21, blablabla" m$(9)= "Knr: 189, Roy, No: 13, blablabla" ' ' Test to sorting string's, on a Name inside the string ' ' using Bubble (or ripple) sort... algorithm ' Dim temp$ As string = "" Dim name1 As string = "" Dim name2 As string = "" arraysize = 9 For i = 1 To arraysize - 1 For j = 1 To arraysize - 1 ' take out Name from strings p = Instr(1,m$(j),",") + 1 ' where is first comma name1 = Mid$(m$(j),p,Len(m$(j))-p) p = Instr(1,m$(j+1),",") + 1 name2 = Mid$(m$(j+1),p,Len(m$(j+1))-p) If name1 > name2 Then temp$ = m$(j) m$(j) = m$(j+1) m$(j+1) = temp$ EndIf Next j Next i ' ' Print out the sorted results... ' Print "--- Result ---" For i = 1 To arraysize Print m$(i) Next i End