Like
| LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
Function: string like(string arg1, string arg2);
See if one word matches part of another.
To use it, you pass the function a value and a mask.
Examples:
like("Susie", "Sus%") will return true, for any value starting with "Sus"
like("Susie", "%Sus%") will return true, for any value containing "Sus"
like("Susie", "%Sus") will return false. This example is looking for a string ending in "Sus".
like("Susie", "Sus") will return false. This example is looking for a string matching only "Sus" exactly.
You can, for example, loop through a list, passing it extracted values from the list and the mask, and it will let you pull out items from the list which are a valid match according to the mask criteria you specified.
Specification
<lsl> integer like(string arg1, string arg2) {
float tmpx; float tmpy;
if(llGetSubString(arg2,0,0)=="%"){
arg2=llGetSubString(arg2,1,-1);tmpy=1;
}
if(llGetSubString(arg2,llStringLength(arg2)-1,-1) == "%") {
arg2=llGetSubString(arg2,0,llStringLength(arg2)-2);tmpy=tmpy+2;
}
if(-1!=(tmpx=llSubStringIndex(arg1,arg2))) {
if((tmpy==0 && llStringLength(arg1)==llStringLength(arg2))
||(tmpy==1 && tmpx == (llStringLength(arg1)- llStringLength(arg2)))
||(tmpy==2 && tmpx == 0)
||(tmpy==3)) {
return TRUE;
}
}
return FALSE;
}
</lsl>
Posted here with the kind permission of Very Keynes. Originally posted February 2008 at http://forums.secondlife.com/showthread.php?t=243445 .