Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Matching Strings

Status
Not open for further replies.

PankajVerma

Programmer
Sep 24, 2001
20
US
I'm using crystal reports 8.5 and trying to match two fields to see if some of the letters in one field are found in the other field.

Example:
field1 = SFOWBUCKN1
field2 = BUCKNER

I need a statement that compares the values of field1 and field2 to return a "true" or "false".

In the above example, this should return a "true"

Example 2:
field1 = SFOWBUTLH1
field2 = BUCKNER

This should return a "false"

Requirements:
The characters should be in the same sequence
The max number of characters to match is 5
The max length of each field I'm comparing is 66

Please help me out.
Regards,
Pankaj
 
Pankaj,

How's this:

If Left(Right({Field1},6),5) = Left({Field2},5)
Then True
Else False;

Naith
 
Hmm...this fix works for this example - but suppose you have a surname consisting of less than 5 characters?

Is the SFOW prefix fixed, or can there be another prefix? If so, can it consist of more than 4 letters? Does field 1 always end in a numeric - or if Field2 is less than 5 characters long, does Field1 end in a char?

Provide a subset of varying examples if the fix in the previous post does not apply universally.

Naith
 
Examples :
field1: "abcdehyutersd"
field2: "sfwreabcdekhhf"
Match found for 5 char "abcde" so it should be true.

Note : Field1 and Field 2 can be less than 5 char also but in that case we don't want to make a match. That can be done by the user him self.

other example
field1: "ndefpankajverma
field2: "vermaabcfhdgsgshde"

Match found for "verma" (5 char) so true.
 
Both hotspots in each field are moving targets. Based on your first and last examples, I would have proposed:

If InStr(Field1,Left(Field2,5)) > 0
Then True
Else False

but in your middle example, you illustrate that it can be any string in the 1st field matching any string in the 2nd field. It is going to be very code intensive to do this without defining first either where the string should be in either field, or stipulate the partial string that you are interested in before hand.

You will have to create a loop which takes the first 5 char block of characters from field1, each time looping through all the letters in field2 until it finds a match. If it does not, you will have to move the 5 char block you are attempting to match by 1 char to the right, and then repeat the process, until you are left with < 5 chars in the field1 variable.

Bear in mind that if you need to do this at a detail level, as I suspect you will, you will be hitting some performance issues.

Naith
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top