Solved

test for inclusion or removal of hyphen or other gramatical character

Posted on 2011-03-22
5
321 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 20

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
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…

726 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