Public Class Form1
Dim PosWrds() As String
Private Sub btnExec_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExec.Click
txtOut.Text = ""
Dim srdFile As New IO.StreamReader("WordList.txt")
Dim WordList() As String = srdFile.ReadToEnd.Split(ControlChars.CrLf)
Dim Words() As String = txtIn.Text.Split(ControlChars.CrLf)
For i As Integer = 0 To Words.Length - 1 'Each word in the list
Words(i) = Words(i).Replace("#", "").Trim 'Remove # and spaces
ReDim PosWrds(0) 'Clear this list
permute(Words(i).Length, Words(i)) 'Find all possible words
Dim mch As Boolean = False
For x As Integer = 0 To PosWrds.Length - 2 'Check every possible word
For y As Integer = 0 To WordList.Length - 1 'Against every word in dictionary
If PosWrds(x).ToString = WordList(y).ToString Then 'If we find a match
txtOut.Text = txtOut.Text & "," & PosWrds(x).ToString 'Output the match
If mch = True Then : Exit For : End If
End If
If mch = True Then : Exit For : End If
Next
Next
Next
txtOut.Text = " " & txtOut.Text 'Just a way to show we finished
'Clipboard.SetText(txtOut.Text.Trim.Remove(0, 1)) 'Save time here
End Sub
Private Sub permute(ByVal length As Integer, ByVal str As String)
Dim array() As Char
array = str
If length > 1 Then
For i As Integer = length - 1 To 0 Step -1
array = str
swap(i, length - 1, array)
permute(length - 1, array)
Next
ElseIf length = 1 Then
PosWrds(PosWrds.Length - 1) = array
ReDim Preserve PosWrds(PosWrds.Length)
End If
End Sub
Private Sub swap(ByVal x As Integer, ByVal y As Integer, ByRef chrArray() As Char)
If x <> y Then
Dim t As Char = chrArray(x)
chrArray(x) = chrArray(y)
chrArray(y) = t
End If
End Sub
End Class