Solved

test for inclusion or removal of hyphen or other gramatical character

Posted on 2011-03-22
5
284 Views
Last Modified: 2012-05-11
I would like a function to pick up if a string has only a minor change:

strcurrent: HI-LUX
strprevious: HILUX

strprevious:HI-LUX LE D/CAB D-4D 4X4 170
strcurrent::HILUX LE D/CAB D-4D 4X4 170

In these examples the function would return false ie no difference
if it could allow for / -

essentially if after removal or inclusion of the characters it matches the original string then there is no difference whereas additional text does make a difference.
I am working in access 2010 vba

0
Comment
Question by:PeterBaileyUk
  • 3
5 Comments
 
LVL 77

Accepted Solution

by:
peter57r earned 250 total points
ID: 35188558
Superficially simple but with the potential for becoming a project on its own.

This is the simple  and NOT comprehensive solution..

It compares two strings, each pass of the loop replaces a the next 'unrequired' character with a designated replacement character (space in this version) and then compares the result.
If at any time the revised strings match the function returns a True value.  Otherwise it reurns False.

Function sameafterremchars(ByVal str1, ByVal str2) As Boolean
Dim remlist As String
Dim curchar As String
Dim x As Long, y As Long
Dim replacewith As String

sameafterremchars = True  ' default is strings are the same
If str1 = str2 Then Exit Function   ' no further tests required
remlist = "-*@"    ' list of characters to be replaced
replacewith = " "   ' replace unwanted characters with this character
y = Len(remlist)
For x = 1 To y
curchar = Mid(remlist, x, 1)
str1 = Replace(str1, curchar, replacewith)
str2 = Replace(str2, curchar, replacewith)
If str1 = str2 Then Exit Function
Next x
' strings not equal if code gets here
sameafterremchars = False
End Function


However, I think you will find this is the thin end of the wedge.  Once you start on this route you will never come to an end. as there will always be another character to test for or another variation which conflicts with an earlier test.

You are heading into 'google search' terrritory (fuzzy matching) and even google doesn't get that right.


0
 

Author Comment

by:PeterBaileyUk
ID: 35188591
understandable I think if i can capture most it will be ok so that the remainder is a word change or addition. On the main part its also experimental if it ( a technique) works great if not then i know i tried.

:)


0
 
LVL 19

Assisted Solution

by:darbid73
darbid73 earned 250 total points
ID: 35188696
I looked at your question and also thought it was in need of a real solution that would take too long to do.

Given peter57r's response I will give you my thoughts in a non-coded way.  But I too think if you go down this track you will be there for a long time.

I was thinking that you could use the following which determines if the character is a letter of the alphabet or not.

Private Function AllLetters(ByVal txt As String) As Boolean
Dim ch As String
Dim i As Integer

    AllLetters = True
    txt = UCase$(txt)
    For i = 1 To Len(txt)
        ' See if the next character is a non-digit.
        ch = Mid$(txt, i, 1)
        If ch < "A" Or ch > "Z" Then
            ' This is not a letter.
            AllLetters = False
            Exit For
        End If
    Next i
End Function

The idea being that you use the MID function to get character no. 1 from both strings and compare this character.  If they are the same you move to the next character.  If they are different and NOT a letter of the alphabet then raise an error or add it to the problem list.
0
 

Author Comment

by:PeterBaileyUk
ID: 35191711
I wonder if its better doing the evaluation word by word:

if the number of words has decreased or increased then flag for attention

if word count the same then

compare each word if the word matches then ignore it until i am down to whats left in the following ex

strprevious:HI-LUX LE D/CAB D-4D 4X4 170
strcurrent::HILUX LE D/CAB D-4D 4X4 170

resolves down to
HI-LUX
HILUX

here i could remove the hyphen and compare if true do nothing however if false then flag.



0
 

Author Closing Comment

by:PeterBaileyUk
ID: 35192145
I have awarded the points anyway despite writing the solution as without your ideas I would not have got there!

thank u both.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now