Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

test for inclusion or removal of hyphen or other gramatical character

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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
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.
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…

604 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