Link to home
Start Free TrialLog in
Avatar of PeterBaileyUk
PeterBaileyUk

asked on

test for additional space

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?

Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

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

Avatar of PeterBaileyUk
PeterBaileyUk

ASKER

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)

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

"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
ASKER CERTIFIED SOLUTION
Avatar of JAMcDo
JAMcDo
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I would use Trim() in your compare.  That would get rid of unnecessary spaces.

If trim(fielda) = Trim(fieldb) then...
worked great thx
Thanks for the points,

J.