Given the lack of a "find()" function in EEL2 I found a function by argitoth and made a few mods:
Code:
function find_string (Pneedle, Phaystack, Pstartpos)
local (i Lfoundpos LlenS LlenT)
(
Lfoundpos = -1;
i = Pstartpos;
LlenS = strlen(Phaystack);
LlenT = strlen(Pneedle);
while(i < LlenS && Lfoundpos < 0) (
strcmp(Pneedle,strcpy_substr(#, Phaystack, i, LlenT)) ? Lfoundpos = -1
: Lfoundpos = i;
i+=1;
);
Lfoundpos;
);
Can you improve this, especially for CPU usage? I want to plough through a TrackStateChunk!
I was tripped up by strcmp() for a while as it returns 0 if the strings match (counter-intuitive, or what?).
I try to make most local variable start with L to make them easier to find in the IDE variable list (just comment out the local lines when debugging).