Page 1 of 1

How to search for a specific string within an input string

Posted: Tue Mar 01, 2011 4:55 am
by saraswati
Hi

I have a input str OPT_STRING="AN3 AY1 B34 B35 C67 DG7 FE1 FE9 FQ3 IKC JB9 JL9 KG7 K05 LZ4 MX0 M15 NK5 NT7 NW9 OSH QB5 QPX UE0 UW6 U1C U19 U2E U77 VC5 VH9 VS7 V73 WD1 WD2 WD7 Z49 1SB 19C 19I 40U 6HM 7HM 8MZ 9MZ"


Now the requirement is:
IF Option code VN9 or VNL exists in the source field OPT_STRING send 'X' else send blank

Note: There is a space between any two option code in the input string i.e.
AN3 AY1, after 3 there is a space.

How to search VN9 and VNL within the input string OPT_STRING?

Posted: Tue Mar 01, 2011 7:52 am
by chulett
Index()

Posted: Tue Mar 01, 2011 3:30 pm
by ray.wurlod
An even more cunning plan - one that cannot fail - is to search for the delimited string.

Code: Select all

If Index(" " : OPT_STRING : " ", " " : OptionCode : " ", 1) Then "X" Else " "

Posted: Tue Mar 01, 2011 4:11 pm
by chulett
Which I would have mentioned if there was any chance for an inadvertent substring match... in this case there isn't, so left that one alone. :wink:

Posted: Tue Mar 01, 2011 5:26 pm
by ray.wurlod
I'm channelling Baldrick today.

Posted: Tue Mar 08, 2011 3:25 am
by saraswati
Index function worked fine for my requirement. Thanks everyone for their help :)

Posted: Thu Mar 10, 2011 3:23 am
by kishore2456
how about matches ?