[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

test for additional space

Posted on 2011-03-08
8
Medium Priority
?
330 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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 2000 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

649 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