Hello Kay,
Good stuff.
I did some time tests and offset() is about twice as fast as matchText(). Don't know why.
Larry

----- Original Message ----- From: "Kay C Lan" <lan.kc.macm...@gmail.com>
To: "How to use LiveCode" <use-livecode@lists.runrev.com>
Sent: Friday, September 26, 2014 12:54 AM
Subject: Re: searching for chars within a string


A simple way would be just to use basic matchText() for each single
letter and regex matchText() for repeating letters.  P.*P will find
double Ps, P.*P.*P will find triple Ps etc. Seems to be relatively
fast but if you have very large data sets other alternatives would
need to be investigated.

in the message box:

put "ABCDEKLP" into X
put "ABCDEKLLLLMMOOPP" into Y
put 100000 into Z
put 0 into a
put 0 into b
put 0 into c
put 0 into d
put the millisec into tStart
repeat Z times
if (matchText(X, "A") AND matchText(X, "E") AND matchText(X, "L") AND
matchText(X, "P.*P")) then
  add 1 to a
else
 add 1 to b
end if
if (matchText(Y, "A") AND matchText(Y, "E") AND matchText(Y, "L") AND
matchText(Y, "P.*P")) then
 add 1 to c
else
add 1 to d
end if
end repeat
put the millisec into tEnd
put "X Passed " & a & " times." & cr into msg
put "X Failed " & b & " times." & cr after msg
put "Y Passed " & c & " times." & cr after msg
put "Y Failed " & d & " times." & cr after msg
put Z & " repeats took " & tEnd - tStart & " ms" after msg

The above should take less than 1 sec but for a million repeats I got:

X Passed 0 times.
X Failed 1000000 times.
Y Passed 1000000 times.
Y Failed 0 times.
1000000 repeats took 1997 ms

NOTE: the above only works if the letters you are looking for can
appear in ANY order. If you need a specific order then you'd have to
regex matchText() for all searches, ie

if (matchText(X, "A.*E.*L.*P") AND matchText(X,"P.*P")) then

Yes, the P must appear in both searches to ensure a P has both an L
before it and a P after it.

HTH

On Wed, Sep 24, 2014 at 8:22 AM,  <la...@significantplanet.org> wrote:
Hello,

I have done a lot research and cannot find any way to do this:

I have a string, "AELPP" and I want to see if all 5 of those letters are in "search string"

If search string is: ABCDEKLP, then NO it isn't because there are two P's in the string I'm searching for.

But if search string is: ABCDEKLLLMMOOPP, then YES the string I'm searching for is found in the search string.

It is important to my program that I just find the 5 chars anywhere within the search string and they do not have to be sequential in the search string.

Thanks for any help,
Larry
_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Reply via email to