Re: coding an anagram function
- From: "Ken Johnson" <KenCJohnson@xxxxxxxxx>
- Date: 20 Oct 2006 04:04:36 -0700
Hi Neil,
I think your idea is OK, it's just easier to use the ASCII code values
to generate LONGs for each text value after removing spaces and
converting to Upper case.
Public Function ISANAGRAM(TEXT1 As String, TEXT2 As String) As Boolean
Application.Volatile
TEXT1 = Replace(TEXT1, " ", "")
TEXT2 = Replace(TEXT2, " ", "")
If Len(TEXT1) <> Len(TEXT2) Then
ISANAGRAM = False
Exit Function
End If
Dim i As Long
Dim lTEXT1_Value As Long
Dim lTEXT2_Value As Long
For i = 1 To Len(TEXT1)
lTEXT1_Value = lTEXT1_Value + 2 ^ (Asc(UCase(Mid(TEXT1, i, 1))) - 64)
lTEXT2_Value = lTEXT2_Value + 2 ^ (Asc(UCase(Mid(TEXT2, i, 1))) - 64)
Next i
If lTEXT1_Value = lTEXT2_Value Then
ISANAGRAM = True
Else: ISANAGRAM = False
End If
End Function
Ken Johnson
.
- Follow-Ups:
- Re: coding an anagram function
- From: N Ramsay
- Re: coding an anagram function
- References:
- coding an anagram function
- From: N Ramsay
- coding an anagram function
- Prev by Date: Re: Copy/paste macro blocking
- Next by Date: Re: coding an anagram function
- Previous by thread: Re: coding an anagram function
- Next by thread: Re: coding an anagram function
- Index(es):
Relevant Pages
|
Loading