Re: coding an anagram function
- From: "Ken Johnson" <KenCJohnson@xxxxxxxxx>
- Date: 20 Oct 2006 07:11:39 -0700
Unless I'm mistaken, the efficiency of Alan's idea can be further
enhanced by...
1. Exiting the inner loop after the condition is first satisfied, since
continuing is a waste of time after the common character has been
located and removed.
2. Exiting the outer loop if a complete run through the inner loop did
not satisfy the condition at all, then a letter in the first string was
not found in the second string and the two are not anagrams.
Public Function ISANAGRAM(TEXT1 As String, TEXT2 As String) As Boolean
Application.Volatile
TEXT1 = UCase(Replace(TEXT1, " ", ""))
TEXT2 = UCase(Replace(TEXT2, " ", ""))
If Len(TEXT1) <> Len(TEXT2) Then
ISANAGRAM = False
Exit Function
End If
Dim I As Long
Dim J As Long
Dim K As Long
For I = 1 To Len(TEXT1)
K = Len(TEXT2)
For J = 1 To Len(TEXT2)
If Mid(TEXT2, J, 1) = Mid(TEXT1, I, 1) Then
Let TEXT2 = Left(TEXT2, J - 1) & Right(TEXT2, Len(TEXT2) - J)
Exit For
End If
Next J
If K = Len(TEXT2) Then
ISANAGRAM = False
Exit Function
End If
Next I
ISANAGRAM = True
End Function
Ken Johnson
.
- References:
- coding an anagram function
- From: N Ramsay
- Re: coding an anagram function
- From: Ken Johnson
- Re: coding an anagram function
- From: N Ramsay
- Re: coding an anagram function
- From: Ken Johnson
- coding an anagram function
- Prev by Date: Re: Copy/paste macro blocking
- Next by Date: ReDim ArrayXY
- Previous by thread: Re: coding an anagram function
- Next by thread: Re: coding an anagram function
- Index(es):
Relevant Pages
|