Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

test for inclusion or removal of hyphen or other gramatical character

Posted on 2011-03-22
5
Medium Priority
?
346 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 1000 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 20

Assisted Solution

by:darbid73
darbid73 earned 1000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses

564 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