| Author |
Message |
oeterrel
Newbie
Joined: 09 Jul 2012
Online Status: Offline
Posts: 4
|

Topic: Finding an element of an array in a string? Posted: 16 Apr 2013 at 2:48am |
|
Good morning,
So I am sure this has to be possible--but I do not know the correct way of coding it. I have two strings. I need to see if any elements of string A are found in string B. String A and B are both function values that return strings. They work fine.
I was trying this code:
global stringvar found; stringvar array x:=split({@string A},","); numbervar j:=ubound(x); stringvar y:=''; stringvar found:='N'; for i:=1 to j do( y:=x; if({@string B} like '*y*') then found:='Y' else found:='N'; )
But the results are random. I have tested the value of y, which returns what I expect--but sometimes the statement of {@string B} like '*y*' is true when it should not be, even though I can get the values of y to return and {@string B} to return and visually see that {@string B} like '*y*' SHOULD be false..
Does a more experienced coder have any ideas?
--Olivia
|
|
As above, so below
|
IP Logged |
|
|
|
joeg1962
Newbie
Joined: 01 Mar 2013
Location: United States
Online Status: Offline
Posts: 35
|

Posted: 16 Apr 2013 at 3:04am |
|
Perhaps an approach like the following (which I use in a report):
if instr({DOCUMENT.SUMMARY}, 'was seen in the emergency') > 0 then 1 else 0
Which checks to see if the variable Document.Summary contains the words 'was seen in the emergency'. I would imagine you could just use your two variables. y checking for >0 is for the position that this occurs; non-zero for a valid position and 0 if not found.
|
IP Logged |
|
oeterrel
Newbie
Joined: 09 Jul 2012
Online Status: Offline
Posts: 4
|

Posted: 16 Apr 2013 at 3:06am |
|
Oh, duh--never mind :) I should say if({@string B} like '*'+y+'*') then found:='Y' of COURSE it was random, since I was looking for parts of the string that had 'y' in them, instead of the value contained in the variable y! (I feel so silly)...
|
|
As above, so below
|
IP Logged |
|
|
|