Maya Mel – Search String in String

Hi,
this is a little script which returns a 0 or 1 if the searched text is in a string. Compared with the match function in mel, this one returns 1 or 0, which is more convenient for my opinion. Furthermore somtimes i get really weired results with the match func().

global proc int ySearch(string $searchWord, string $searchInText){

string $longText = $searchInText;
string $shortText = $searchWord;
int $i = 0;
int $j = 0;
string $searchText = “”;
for($i = 1; $i <= (size($longText)-1); $i++){
for($j = $i; $j <= size($longText); $j++){
$searchText = substring($longText, $i, $j);
//print(” i ” + $i + ” ” + $j + ” j \n”);
if ($searchText == $shortText){
return 1;
//print(“drinnen”);
}

}

}
return 0;
}

//Usage:
ySearch(“where is schiho today?”, “schiho”);

//Result: 1

No Comments

Add Comment