+ Reply to Thread
Results 1 to 4 of 4

Compare data strings?

  1. #1
    Ed
    Guest

    Compare data strings?

    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



  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    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.

    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

  3. #3
    Dave Peterson
    Guest

    Re: Compare data strings?

    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

  4. #4
    Ed
    Guest

    Re: Compare data strings?

    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




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1