Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
Compare data strings?
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. Code: -------------------- 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 -------------------- Sincerely, Leith Ross -- Leith Ross ------------------------------------------------------------------------ Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465 View this thread: http://www.excelforum.com/showthread...hreadid=493209 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
Compare data strings?
Very nice, Dave!! Thank you!
Ed "Dave Peterson" wrote in message ... 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 |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Compare Strings | Excel Discussion (Misc queries) | |||
Compare two strings | Excel Worksheet Functions | |||
Compare strings of data | Excel Programming | |||
Compare the strings | Excel Discussion (Misc queries) | |||
VBA search and compare strings | Excel Programming |