Checking for a string but...

Thread: Checking for a string but...

1. Senior Member
Join Date
Dec 1969
Posts
936

Checking for a string but...

I have a string: <BR><BR>The Royal Bank of Scotland Plc<BR>12 Golden Square<BR>Berrick<BR>Berrickshire<BR><BR>What I want to check for is the string "Berrick" but at the moment it will pick up the "Berrick" and the "Berrickshire" bit. So if an address had just Berrickshire it would flag when I don&#039;t want it to.<BR><BR>How would I do this?<BR><BR>Thanks,<BR>Jamie

2. Senior Member
Join Date
Dec 1969
Posts
11,247

RE: Checking for a string but...

Show your code...<BR><BR>And BTW it is Berwick &#060;-- My home town

3. Senior Member
Join Date
Dec 1969
Posts
936

RE: Checking for a string but...

I changed the names...<BR><BR>Here&#039;s my code for building the string:<BR> If line1 &#060;&#062; "" then <BR> OutputAddress = line1 & Chr(10)<BR> End If <BR> If line2 &#060;&#062; "" then <BR> OutputAddress = OutputAddress & line2 & Chr(10)<BR> End If <BR> If line3 &#060;&#062; "" then <BR> OutputAddress = OutputAddress & line3 & Chr(10)<BR> End If <BR> If line4 &#060;&#062; "" then <BR> OutputAddress = OutputAddress & line4 & Chr(10)<BR> End If<BR><BR>If OutputAddress

4. Senior Member
Join Date
Dec 1969
Posts
11,247

RE: Checking for a string but...

Stringlookingfor = "Berwick"<BR>&#039;I used instr then thought that will find in line4 as well So<BR>&#039;You can do a straight <BR>if (line3 = stringlookingfor) then<BR>&#039;After all Berwick &#060;&#062; Berwickshire<BR>...<BR>If line3 &#060;&#062; "" then<BR> OutputAddress = OutputAddress & line3 & Chr(10)<BR> If instr(1, Stringlookingfor, line3) &#060;&#062; 0 Then<BR> &#039;Hello we found it!<BR> end if<BR>End If ...

5. Senior Member
Join Date
Dec 1969
Posts
936

RE: Checking for a string but...

The only thing is that Berwick could be on line2, line3, line4 i.e. anywhere within the OutputAddress. What happens in this case?

6. Senior Member
Join Date
Dec 1969
Posts
5,955

You do an OR compare with all the lines...

...likes this:<BR><BR>if (line2 = stringlookingfor or line3 = stringlookingfor or line4 = stringlookingfor) then <BR><BR><BR>If this is true, you found the search string in either one or more of the address lines.<BR><BR>Hey presto, :-)<BR>Oliver.

7. Senior Member
Join Date
Dec 1969
Posts
936

RE: You do an OR compare with all the lines...

I should have underlined "anywhere within"<BR><BR>anywhere within the OutputAddress

8. Senior Member
Join Date
Dec 1969
Posts
5,955

How do you mean? Can you give me...

...a few examples of what you&#039;re trying to find?<BR><BR>Oliver.

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•