Login  Register

Re: Array of strings- a macro question

Posted by George Patterson on Aug 05, 2015; 1:57pm
URL: http://imagej.273.s1.nabble.com/Array-of-strings-a-macro-question-tp5013893p5013906.html

Hi Guy,
The matches(string, regex) function is probably what you want to compare
two strings, but it sounds like you want to search for a substring within a
larger string.
I've pasted a little function below which I've used to search for a string
inside a longer string.  There might be a function already in the macro
language to do this, but I wasn't able to find it at the time I assembled
the script below.  It's pretty crude, but seemed to get the job done for
me.  You might be able to modify it for your use.  If you find a bug or
more likely many bugs please let me know.
Best,
George

function checkForMatches(fragSeq,checkSeq){
numMatchesFound=0;
//print("fragSeq="+fragSeq+"   checkSeq="+checkSeq);
if(lengthOf(fragSeq)>lengthOf(checkSeq)){
return false;
}
for(i=0;i<=lengthOf(checkSeq)-lengthOf(fragSeq);i++){
if(matches(fragSeq,substring(checkSeq,i,i+lengthOf(fragSeq)))){
numMatchesFound++;
}
}
print("numMatchesFound="+numMatchesFound);
if(numMatchesFound>0){
return true;
}else{
return false;
}
}

On Wed, Aug 5, 2015 at 3:35 AM, Guy Malkinson <
[hidden email]> wrote:

> Hey Volko,
> Thanks.
> Yes, I've seen these functions, but they don't seem to be helpful for my
> case (as I'm looking to work with substring occurences in the middle of the
> original string).
> All the best
> Guy
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html