Imports System
Imports System.Collections.Generic
Public Class Program
Private Const SIZE As Integer = 256
Public Shared Function Compare(ByVal arr_str As Byte(), ByVal arr_sub As Byte()) As Boolean
For i As Integer = 0 To SIZE - 1
If arr_str(i) <> arr_sub(i) Then Return False
Next
Return True
End Function
Public Shared Function find_substring_permutations(ByVal str As String, ByVal substr As String) As List(Of Integer)
Dim result_list As List(Of Integer) = New List(Of Integer)()
Dim countSub As Byte() = New Byte(255) {}
Dim countStr As Byte() = New Byte(255) {}
For i As Integer = 0 To substr.Length - 1
countSub(Asc(substr(i))) = countSub(Asc(substr(i))) + 1
countStr(Asc(str(i))) = countStr(Asc(str(i))) + 1
Next
For i As Integer = substr.Length To str.Length - 1
If Compare(countSub, countStr) Then result_list.Add(i - substr.Length)
countStr(Asc(str(i))) = countStr(Asc(str(i))) + 1
countStr(Asc(str(i - substr.Length))) = countStr(Asc(str(i - substr.Length))) - 1
Next
If Compare(countSub, countStr) Then result_list.Add(str.Length - substr.Length)
Return result_list
End Function
Public Shared Sub Main()
' 0 CBA : 5 BAC : 11 ABC : 12 BCA : 13 CAB : 21 ACB : 26 CAB
Dim s As String = "CBAxyBACdarABCABbcapoACBqtCAB"
Dim substr As String = "ABC"
Dim result As List(Of Integer) = find_substring_permutations(s, substr)
For Each n As Integer In result
Console.Write(n & " ")
Next
End Sub
End Class
' run
'
' 0 5 11 12 13 21 26
'