I have a series of data strings I need to compare. I am looking for the one
string that has a character found in no other string. What is the best way
to approach this?
Ed
I have a series of data strings I need to compare. I am looking for the one
string that has a character found in no other string. What is the best way
to approach this?
Ed
Hello Ed,
This routine scans a string character by character and stores the number of times the character is found in an array. The array has 256 elements, one for each ASCII value. The result is a final string that will contain the unique characters found. A unique character is one that appears only once.
Sincerely,Sub FindUniqueCharacters() Dim Chars(255) As Integer Dim N As Integer Dim TestStr As String TestStr = "ABCDEFABCDeF" For I = 1 To Len(TestStr) N = Asc(Mid(TestStr, I, 1)) Chars(N) = Chars(N) + 1 Next I For I = 0 To 255 If Chars(I) = 1 Then S = S & Chr$(I) End If Next I End Sub
Leith Ross
This seems to work ok:
Option Explicit
Sub testme()
Dim myWords As Variant
Dim iCtr As Long
Dim wCtr As Long
Dim lCtr As Long
Dim myStr As String
myWords = Array("one", "two", "three", "four")
For wCtr = LBound(myWords) To UBound(myWords)
myStr = ""
For iCtr = LBound(myWords) To UBound(myWords)
If wCtr = iCtr Then
'do nothing
Else
myStr = myStr & myWords(iCtr)
End If
Next iCtr
For lCtr = 1 To Len(myWords(wCtr))
If InStr(1, myStr, Mid(myWords(wCtr), lCtr, 1), _
vbTextCompare) = 0 Then
MsgBox Mid(myWords(wCtr), lCtr, 1) & " in " & myWords(wCtr) _
& vbLf & " is not used in any other word!"
End If
Next lCtr
Next wCtr
End Sub
Ed wrote:
>
> I have a series of data strings I need to compare. I am looking for the one
> string that has a character found in no other string. What is the best way
> to approach this?
>
> Ed
--
Dave Peterson
Very nice, Dave!! Thank you!
Ed
"Dave Peterson" <[email protected]> wrote in message
news:[email protected]...
> This seems to work ok:
>
> Option Explicit
> Sub testme()
>
> Dim myWords As Variant
> Dim iCtr As Long
> Dim wCtr As Long
> Dim lCtr As Long
> Dim myStr As String
>
> myWords = Array("one", "two", "three", "four")
>
> For wCtr = LBound(myWords) To UBound(myWords)
> myStr = ""
> For iCtr = LBound(myWords) To UBound(myWords)
> If wCtr = iCtr Then
> 'do nothing
> Else
> myStr = myStr & myWords(iCtr)
> End If
> Next iCtr
>
> For lCtr = 1 To Len(myWords(wCtr))
> If InStr(1, myStr, Mid(myWords(wCtr), lCtr, 1), _
> vbTextCompare) = 0 Then
> MsgBox Mid(myWords(wCtr), lCtr, 1) & " in " &
myWords(wCtr) _
> & vbLf & " is not used in any other word!"
> End If
> Next lCtr
>
> Next wCtr
>
> End Sub
>
>
> Ed wrote:
> >
> > I have a series of data strings I need to compare. I am looking for the
one
> > string that has a character found in no other string. What is the best
way
> > to approach this?
> >
> > Ed
>
> --
>
> Dave Peterson
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks