Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ed Ed is offline
external usenet poster
 
Posts: 399
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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   Report Post  
Posted to microsoft.public.excel.programming
Ed Ed is offline
external usenet poster
 
Posts: 399
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compare Strings dksaluki Excel Discussion (Misc queries) 4 October 18th 08 09:39 PM
Compare two strings andy62 Excel Worksheet Functions 8 September 6th 06 02:14 PM
Compare strings of data Hal Excel Programming 1 September 28th 05 04:50 PM
Compare the strings yangyh Excel Discussion (Misc queries) 3 September 8th 05 04:45 AM
VBA search and compare strings stuart Excel Programming 1 June 11th 04 01:00 AM


All times are GMT +1. The time now is 02:13 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"