Solved

test for additional space

Posted on 2011-03-08
8
324 Views
Last Modified: 2012-06-27
I would like to test two strings to see if a space has been added.

str1 "100S LWB CH5S"

str2 "100 S LWB CH5S"

The string is essentially the same text but only had a space added at some part.

Is that possible to test for

ie determine if space added and if added add the space temporarily to str1 and then do a compare to make sure they are equal strings?

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
  • 2
  • 2
  • +1
8 Comments
 
LVL 75
ID: 35079209
Well, you can use StrComp to see if the are equal or note:

example:

strcomp("100S LWB CH5S","100 S LWB CH5S")

returns 1 because they are not equal

StrComp returns :
string1 is less than string2 -1
string1 is equal to string2 0
string1 is greater than string2 1
string1 or string2 is Null Null

mx

0
 

Author Comment

by:PeterBaileyUk
ID: 35079750
and is it easy to find where the space belongs in field 1?

i am thinking maybe checking each character until they dont match and at that point string2(position string1 +1) should be a space and if it is then add a space at string1(position)

0
 

Author Comment

by:PeterBaileyUk
ID: 35079770
or another thought find current space positions in string2

string 1 positions should correspond to string 2 bar 1 and thats my insertion point on string 1

0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
LVL 75
ID: 35079809
"or another thought find current space positions in string2"
You can use the InStr() function to find the first occurrence of a Space (or any character)

InStr(1,SearchString, SearchingFor) returns the first position fo Searching For

InStr(1,"100 S LWB CH5S", " ") returns 4

mx
0
 
LVL 3

Accepted Solution

by:
JAMcDo earned 500 total points
ID: 35079988
You may wish to try this function:

Function MakeEqualStr(Str1 As String, Str2 As String) As String

    Dim Pntr As Integer
    Dim MaxPntr As Integer
   
    Pntr = 1
       
    MaxPntr = IIf(Len(Str1) < Len(Str2), Len(Str1), Len(Str2))
   
    Do While StrComp(Str1, Str2) <> 0
        Select Case StrComp(Left$(Str1, Pntr), Left$(Str2, Pntr))
            Case -1
                Str2 = Left$(Str1, Pntr) & Mid$(Str2, Pntr)
            Case 1
                Str1 = Left$(Str2, Pntr) & Mid$(Str1, Pntr)
            Case 0
                Pntr = Pntr + 1
                If Pntr > MaxPntr Then Exit Do
        End Select
    Loop
    MakeEqualStr = Str1
End Function

Create -> Module and copy/paste the function into a module.

J.
0
 
LVL 77

Expert Comment

by:peter57r
ID: 35080344
I would use Trim() in your compare.  That would get rid of unnecessary spaces.

If trim(fielda) = Trim(fieldb) then...
0
 

Author Closing Comment

by:PeterBaileyUk
ID: 35081078
worked great thx
0
 
LVL 3

Expert Comment

by:JAMcDo
ID: 35081435
Thanks for the points,

J.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

756 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